zoukankan      html  css  js  c++  java
  • HDU 4722 Good Numbers

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722

    Good Numbers

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 422    Accepted Submission(s): 146


    Problem Description
    If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number.
    You are required to count the number of good numbers in the range from A to B, inclusive.
     
    Input
    The first line has a number T (T <= 10000) , indicating the number of test cases.
    Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).
     
    Output
    For test case X, output "Case #X: " first, then output the number of good numbers in a single line.
     
    Sample Input
    2
    1 10
    1 20
     
    Sample Output
    Case #1: 0
    Case #2: 1
     
    题目大意:找出给定范围内数位和能被10整除的数的数目
     
    解题思路:不难发现,以100个数为一组,每组有10个数满足条件,对于给定的数,先找有多少组,对剩余的数暴搜一遍就能得到结果。
     
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 int keng(long long x,int left)
     7 {
     8     int n=0,i,ans;
     9     while(x)
    10     {
    11         n+=x%10;
    12         n%=10;
    13         x/=10;
    14     }
    15     ans=left/10;
    16     i=10-(n+ans)%10;
    17         if(i==10)
    18             i=0;
    19     if(left%10>=i)
    20         ans++;
    21     return ans;
    22 }
    23 bool check(long long a)
    24 {
    25     int n=0;
    26     while(a)
    27     {
    28         n+=a%10;
    29         n%=10;
    30         a/=10;
    31     }
    32     if(n%10==0)
    33         return true;
    34     else return false;
    35 }
    36 int main()
    37 {
    38     int t,i,Case,shu;
    39     long long a,b;
    40     long long Ca,Cb;
    41     long long left;
    42     scanf("%d",&t);
    43     // a=1;
    44     for(Case=1;Case<=t;Case++)
    45     {
    46         // b=Case;
    47         scanf("%I64d%I64d",&a,&b);
    48         Ca=a/100*10;left=a%100;
    49         Ca=keng(Ca/10,left)+Ca;
    50         if (check(a)) Ca--;
    51         Cb=b/100*10;left=b%100;
    52         Cb=keng(Cb/10,left)+Cb;
    53         printf("Case #%d: %I64d
    ",Case,Cb-Ca);
    54     }
    55     return 0;
    56 } 
    View Code
  • 相关阅读:
    event.keycode大全(javascript) (转)
    Javascript 中的 字符串对象 toUpperCase() toString() charAt() indexOf() lastIndexOf() replace() search() substring()
    Javascript 中的 var
    Javascript 中的 Array
    super() (1)
    Javascript 中的事件
    JavaScript验证函数大全 (转)
    javascript数字验证(转)
    Javascript 中 null 与 undefined关系
    Javascript 中的 for ... in
  • 原文地址:https://www.cnblogs.com/wuwing/p/3315902.html
Copyright © 2011-2022 走看看