HDU 5327 Olympiad (多校)

來源:互聯網
上載者:User

標籤:

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 (多校)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.