HDU 4151 The Special Number【二分+暴力枚举】

Problem Description
In this problem, we assume the positive integer with the following properties are called ‘the special number’:
1) The special number is a non-negative integer without any leading zero.
2) The numbers in every digit of the special number is unique ,in decimal system.
Of course,it is easy to check whether one integer is a ‘special number’ or not, for instances, 1532 is the ‘special number’ and 101 is not. However, we just want to know the quantity of the special numbers that is less than N in this problem.
Input
The input will consist of a series of signed integers which are not bigger than 10,000,000. one integer per line. (You may assume that there are no more than 20000 test cases)
Output
For each case, output the quantity of the special numbers that is less than N in a single line.
Sample Input
10
12
Sample Output
9
10
code:
View Code
#include<stdio.h>
#include<string.h>
int a[1000000];
int main()
{
int b[10];
int i,j,n,k,low,high,mid;
k=1;
for(i=1;i<=10000000;i++)
{
memset(b,0,sizeof(b));
j=i;
while(j)
{
if(b[j%10]!=1)
{
b[j%10]=1;
j/=10;}
else break;
}
if(j==0)
a[k++]=i;
}
while(scanf("%d",&n)!=EOF)
{
if(n<=1)
printf("0\n");
else
{
low=1;
high=k-1;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]>=n)
high=mid-1;
else low=mid+1;
}
printf("%d\n",high);
}
}
return 0;
}

posted @ 2012-03-16 12:36  'wind  阅读(551)  评论(0编辑  收藏  举报