题意:用x和y组成不大于n的整数有多少个(0?≤?x,? y?≤?9,1?≤?n?≤?10^9)。
题目链接:http://codeforces.com/problemset/problem/244/B
——>>枚举x, y,将其所有组成的数放入set,最后看set里有多少个元素就好。
#include <cstdio>
#include <set>using namespace std;int n;
set<long long> se;void Find(int x, int y, long long cur){long long getx = cur * 10 + x;long long gety = cur * 10 + y;if(getx && getx <= n){se.insert(getx);Find(x, y, getx);}if(gety <= n){se.insert(gety);Find(x, y, gety);}
}int main()
{while(scanf("%d", &n) == 1){se.clear();for(int x = 0; x < 9; x++)for(int y = x + 1; y <= 9; y++)Find(x, y, 0);printf("%d\n", se.size());}return 0;
}