zoukankan      html  css  js  c++  java
  • HDU 5327 Olympiad (多校)

    Olympiad

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 631    Accepted Submission(s): 436


    Problem Description
    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). Please be fast to get the gold medal!
     
    Input
    The first line of the input is a single integer T (T1000), 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 1ab100000.
     
    Output
    For each testcase, print one line indicating the answer.
     
    Sample Input
    2 1 10 1 1000
     
    Sample Output
    10 738
     
    Author
    XJZX
     
    Source
     
    Recommend
    wange2014   |   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 12
    10 
    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 }
  • 相关阅读:
    bzoj3687 简单题
    bzoj3992 [SDOI2015]序列统计
    bzoj4602 [Sdoi2016]齿轮
    bzoj4006 [JLOI2015]管道连接
    szoj461【四校联考0430】挑战
    bzoj4037 [HAOI2015]数字串拆分
    javascript 节点的增,删,改,查
    javascript 节点属性详解
    表单操作部分
    文档对象的操作
  • 原文地址:https://www.cnblogs.com/wmxl/p/4703093.html
Copyright © 2011-2022 走看看