標籤:
Olympiad
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 631 Accepted Submission(s): 436
Problem DescriptionYou are one of the competitors of the Olympiad in numbers. The problem of this year relates to beatiful numbers. One integer is called beautiful if and only if all of its digitals are different (i.e. 12345 is beautiful, 11 is not beautiful and 100 is not beautiful). Every time you are asked to count how many beautiful numbers there are in the interval [a,b] (a≤b). Please be fast to get the gold medal!
InputThe first line of the input is a single integer T (T≤1000), indicating the number of testcases.
For each test case, there are two numbers a and b, as described in the statement. It is guaranteed that 1≤a≤b≤100000.
OutputFor each testcase, print one line indicating the answer.
Sample Input21 101 1000
Sample Output10738
AuthorXJZX
Source 2015 Multi-University Training Contest 4
Recommendwange2014 | We have carefully selected several similar problems for you: 5352 5351 5350 5349 5348 開始想用字串做,推出每一個數之前的美麗數的總和,再將a,b的總和數相減就是它們之間的美麗數之和了。但是做了半天還是沒做出來,太麻煩。題解的做法是預先處理,把每一個數是不是美麗數都判一遍,判的過程中用一個數組f記錄這之前的美麗數之和,最後也是兩個相減,也就是f[b]-f[a-1].
1 #include<queue> 2 #include<math.h> 3 #include<stdio.h> 4 #include<string.h> 5 #include<iostream> 6 #include<algorithm> 7 using namespace std; 8 #define N 123456 9 #define M 1210 11 int a,b;12 int ha[M],f[N];13 int judge(int x)14 {15 int n;16 memset(ha,0,sizeof(ha));17 while(x)18 {19 n=x%10;20 if(ha[n])return 0;21 else ha[n]=1;22 x=x/10;23 }24 return 1;25 }26 27 int main()28 {29 f[0]=1;30 for(int i=1;i<100005;i++)31 {32 f[i]=f[i-1];33 if( judge(i) )34 f[i]++;35 }36 int t;cin>>t;37 while(t--)38 {39 scanf("%d%d",&a,&b);40 cout<<f[b]-f[a-1]<<endl;41 }42 return 0;43 }
HDU 5327 Olympiad (多校)