题目链接: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=,i,ans;
  9. while(x)
  10. {
  11. n+=x%;
  12. n%=;
  13. x/=;
  14. }
  15. ans=left/;
  16. i=-(n+ans)%;
  17. if(i==)
  18. i=;
  19. if(left%>=i)
  20. ans++;
  21. return ans;
  22. }
  23. bool check(long long a)
  24. {
  25. int n=;
  26. while(a)
  27. {
  28. n+=a%;
  29. n%=;
  30. a/=;
  31. }
  32. if(n%==)
  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=;Case<=t;Case++)
  45. {
  46. // b=Case;
  47. scanf("%I64d%I64d",&a,&b);
  48. Ca=a/*;left=a%;
  49. Ca=keng(Ca/,left)+Ca;
  50. if (check(a)) Ca--;
  51. Cb=b/*;left=b%;
  52. Cb=keng(Cb/,left)+Cb;
  53. printf("Case #%d: %I64d\n",Case,Cb-Ca);
  54. }
  55. return ;
  56. }

HDU 4722 Good Numbers的更多相关文章

  1. 【数位DP】 HDU 4722 Good Numbers

    原题直通车: HDU  4722  Good Numbers 题意: 求区间[a,b]中各位数和mod 10==0的个数. 代码: #include<iostream> #include& ...

  2. hdu 4722 Good Numbers(规律题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4722 [题意]: 找GoodNumbers一个数N,如果它每一个位数字之和可以整除10,那么它就是GoodNum ...

  3. HDU 4722 Good Numbers 2013年四川省赛题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 题目大意:给定一个区间,求区间中有多少个满足每位上的数的和是10的倍数. 解题思路:先打表暴力求 ...

  4. HDU 4722 Good Numbers(位数DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)

    Description If we sum up every digit of a number and the result can be exactly divided by 10, we say ...

  5. hdu 4722 Good Numbers 规律 数位dp

    #include<iostream> #include<cstring> #include<cstdio> #include<vector> #incl ...

  6. hdu 4722 Good Numbers( 数位dp入门)

    Good Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. HDU - 4722 Good Numbers 【找规律 or 数位dp模板】

    If we sum up every digit of a number and the result can be exactly divided by 10, we say this number ...

  8. HDU 4722 Good Numbers(DP)

    题目链接 脑子有点乱,有的地方写错了,尚大婶鄙视了... 来个模版的. #include <iostream> #include <cstdio> #include <c ...

  9. hdu 4722 Good Numbers 数位DP

    数位DP!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include< ...

随机推荐

  1. Uploadify 上传失败

    更改Apache的php.ini的配置 In my php.ini (created custom ini file in public_html) would this solve this pro ...

  2. 收藏一个匹配html内容的文章

    http://blog.csdn.net/donglynn/article/details/35788879

  3. Sass中常用的函数

    字符串函数 To-upper-case() 函数将字符串小写字母转换成大写字母 To-lower-case() 函数 与 To-upper-case() 刚好相反,将字符串转换成小写字母 数字函数 S ...

  4. php提取背景图片

    preg_match_all('/background\s*-\s*+image\s*:\s*url\s*\("*([^"]*)"*\)/i', $content,$ma ...

  5. lucene解决全文检索word2003,word2007的办法

    在上一篇文章中 ,lucene只能全文检索word2003,无法检索2007,并且只能加载部分内容,无法加载全文内容.为解决此问题,找到了如下方法 POI 读取word (word 2003 和 wo ...

  6. Remark of BLENDFUNCTION from MSDN

    Remarks When the AlphaFormat member is AC_SRC_ALPHA, the source bitmap must be 32 bpp. If it is not, ...

  7. 黑马程序员-------.net基础知识五

    方法(函数) 作用:用来重复代码,当我们在一个过程中反复的写了同样的代码,一般情况下,我们就可以把需要重复写的代码定义在方法中,用的时候只需调用即可 语法: [访问修饰符][static] 返回值类型 ...

  8. asp.net mvc4 Controller与Action执行过程的研究(学习笔记)

    当IIS收到一个http请求,把请求信息发给对应的HttpModel(实际是实现类UrlRoutingModule),在HttpModel中会注册HttpApplication 类中的PostReso ...

  9. 解决android模拟器太大,小屏幕无法完全显示的问题

    http://hi.baidu.com/conanx/blog/item/05479befd6534d03fdfa3cbb.html 安装上Android模拟器之后,开启一个Android 2.2的模 ...

  10. Python的数据类型总结

    原地可变类型和不可变类型 原地不可变类型又叫可哈希(hashable)类型,原地可变类型又叫不可哈希类型. 原地不可变类型: 数字类型:int, float, decimal.Decimal, fra ...