题目链接:
http://codeforces.com/problemset/problem/244/B
题目大意:
有两个个位数x,y,可以组合成许多新的数,那么这些数的不同的位数最多为2,求出这些数小于等于n的个数。
思路:
因为要求组合出的数,所以可以通过对x,y进行枚举,得到小于n的数,放入set里面,最后set里面的数的数量就是答案。
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<set>
#define LL __int64
using namespace std;
set<LL>st;
LL n;
void dfs(LL x,LL y,LL ans)
{
st.insert(ans);
LL fx=ans*10+x;
LL fy=ans*10+y;
if(fx&&fx<=n)
dfs(x,y,fx);
if(fy&&fy<=n)
dfs(x,y,fy);
return ;
}
int main()
{
LL x,y,i,j,k;
while(scanf("%I64d",&n)!=EOF)
{
st.clear();
for(i=0;i<=9;i++)
{
for(j=0;j<=9;j++)
{
dfs(i,j,0);
}
}
printf("%d\n",st.size());
}
}