I - Olympiad

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了I - Olympiad相关的知识,希望对你有一定的参考价值。

You 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] (ab)[a,b] (a≤b). Please be fast to get the gold medal! 

InputThe first line of the input is a single integer T (T1000)T (T≤1000), indicating the number of testcases. 

For each test case, there are two numbers aa and bb, as described in the statement. It is guaranteed that 1ab1000001≤a≤b≤100000. 
OutputFor each testcase, print one line indicating the answer. 
Sample Input

2
1 10
1 1000

Sample Output

10
738
打表大法好呀
技术分享
 1 #include <iostream>
 2 using namespace std;
 3 #include<string.h>
 4 #include<set>
 5 #include<stdio.h>
 6 #include<math.h>
 7 #include<queue>
 8 #include<map>
 9 #include<algorithm>
10 #include<cstdio>
11 #include<cmath>
12 #include<cstring>
13 #include <cstdio>
14 #include <cstdlib>
15 #include<cstring>
16 int a[1000010],b[15];
17 int guanyinzuolian(int n)
18 {
19     memset(b,0,sizeof(b));
20     while(n!=0)
21     {
22         if(b[n%10])
23             return 0;
24         b[n%10]++;
25         n/=10;
26     }
27     return 1;
28 }
29 void lubenwei()
30 {
31     int sum=0;
32     for(int i=1;i<=100000;i++)
33         a[i]=a[i-1]+guanyinzuolian(i);
34 }
35 int main()
36 {
37     memset(a,0,sizeof(a));
38     lubenwei();
39     int t;
40     cin>>t;
41     while(t--)
42     {
43         int n,m;
44         cin>>n>>m;
45         cout<<a[m]-a[n-1]<<endl;
46     }
47 }
View Code

 







以上是关于I - Olympiad的主要内容,如果未能解决你的问题,请参考以下文章

Olympiad

Codeforces Round #680 (Div. 2, based on Moscow Team Olympiad)ABCD

Codeforces Round #626 (Div. 1, based on Moscow Open Olympiad in Informatics)B(位运算,二分查找)

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A. Fraction

Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)(A-C)

CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)