题目链接: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个数满足条件,对于给定的数,先找有多少组,对剩余的数暴搜一遍就能得到结果。
 
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int keng(long long x,int left)
{
int n=,i,ans;
while(x)
{
n+=x%;
n%=;
x/=;
}
ans=left/;
i=-(n+ans)%;
if(i==)
i=;
if(left%>=i)
ans++;
return ans;
}
bool check(long long a)
{
int n=;
while(a)
{
n+=a%;
n%=;
a/=;
}
if(n%==)
return true;
else return false;
}
int main()
{
int t,i,Case,shu;
long long a,b;
long long Ca,Cb;
long long left;
scanf("%d",&t);
// a=1;
for(Case=;Case<=t;Case++)
{
// b=Case;
scanf("%I64d%I64d",&a,&b);
Ca=a/*;left=a%;
Ca=keng(Ca/,left)+Ca;
if (check(a)) Ca--;
Cb=b/*;left=b%;
Cb=keng(Cb/,left)+Cb;
printf("Case #%d: %I64d\n",Case,Cb-Ca);
}
return ;
}

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. dom 笔记

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Android中图片的异步加载

    转: 1.  为什么要异步加载图片 下载图片比较费时,先显示文字部分,让加载图片的过程在后台,以提升用户体验 2.  SoftReference的作用 栈内存—引用 堆内存—对象 Eg: Object ...

  3. HTML5学习笔记----html5与传统html区别

    一. HTML5语法的改变 该知识点所说变化指的是基于HTML4基础上所定义的改变,主要有如下: HTML5的文件扩展符(.html或.htm)与内容类型(text/html)保持不变. HTML5中 ...

  4. 服务端生成word并压缩打包下载

    所需工具 phpwrod 库 php_zip 扩展 下载phpword库,放到类加载路径. 安装php_zip扩展 下载地址 http://pecl.php.net/package/zip linux ...

  5. Python里隐藏的 " 诗 "

    在 Python 的Lib目录里有一个:this.Py (或者在交互式解释器中输入import this) 它其实是隐藏的一首诗 The Zen of Python, by Tim Peters &l ...

  6. Python Tips and Traps(二)

    6.collections 模块还提供有OrderedDict,用于获取有序字典 import collections d = {'b':3, 'a':1,'x':4 ,'z':2} dd = col ...

  7. POJ 3126 Prime Path 素数筛,bfs

    题目: http://poj.org/problem?id=3126 困得不行了,没想到敲完一遍直接就A了,16ms,debug环节都没进行.人品啊. #include <stdio.h> ...

  8. 解决CocoaPods在OS X 10.11出现问题-b

    最近把mac系统升级到10.11系统,但是在用pod install命令的时候,却提示command not found.后来上网查了下才知道,Cocoapods在10.11系统上发生了变化. 在st ...

  9. Solve Longest Path Problem in linear time

    We know that the longest path problem for general case belongs to the NP-hard category, so there is ...

  10. Z-stack之OSAL初始化流程

    转自点击打开链接 我使用的协议栈版本及例子信息: ZigBee2006\Texas Instruments\ZStack-1.4.3-1.2.1\Projects\zstack\Samples\Sam ...