题目链接: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. JS将搜索的关键字高亮显示实现代码

    这篇文章介绍了JS将搜索的关键字高亮显示实现代码,有需要的朋友可以参考一下 用JS让文章内容指定的关键字加亮 是这样的.. 现在有这些关键字:美容,生活,购物 当在文章里头出现这些关键字,就把它加亮显 ...

  2. 【javascript 变量和作用域】

    今天学习了javascript 的变量和作用域的基本知识,对于以前在开发中遇到的一些不懂的小问题也有了系统的认识,收获还是比较多的. [基本类型和引用类型] ECMAScript 变量可能包含两种不同 ...

  3. python入门第一天作业。讲师写的代码。

    #!/uer/bin/env python # _*_ coding: utf-8 _*_ import sys retry_limit = 3 retry_count = 0 account_fil ...

  4. poj 1681 Painter's Problem

    Painter's Problem 题意:给一个n*n(1 <= n <= 15)具有初始颜色(颜色只有yellow&white两种,即01矩阵)的square染色,每次对一个方格 ...

  5. 密室经典逃脱N部--考验你的智力!据说全球没几人走出去!不要看攻略!【工作之余也来休闲一下】

    密室经典逃脱N部-考验你的智力!据说全球没几人走出去!不要看攻略![工作之余也来休闲一下] 更多经典逃脱尽在:点击进入更多经典逃脱 测试你的反映速度:躲避小红球 测试你对鼠标的控制力 叫美女起床 ↓↓ ...

  6. 用JS实现避免重复加载相同js文件

    我们在日常开发过程中,可能有重复加载同一个资源例如:1.js,为了提高性能和用户体验这里我们用原生JS实现同一个资源只加载一次. 下面是 common.js里的JS代码 //使用沙箱模式防止污染外面的 ...

  7. windows appfabric samples

    http://www.microsoft.com/en-us/download/details.aspx?id=19603 http://msdn.microsoft.com/zh-cn/librar ...

  8. 使用ImageMagick和Tesseract进行简单数字图像识别

    使用ImageMagick和Tesseract进行简单数字图像识别 由于直接使用 tesseract 进行识别,识别率很低, ImageMagick 安装.配置及使用: 平台:winXP 1. 安装I ...

  9. hdu 1269

    强连通分量题,用tarjin算法: 这是一道很简单的tarjin算法题,基本上就是套模板: 贴代码: #include<cstdio> #include<vector> #in ...

  10. ThinkPHP3.1快速入门(3)查询语言

    http://www.thinkphp.cn/info/115.html 介绍 ThinkPHP内置了非常灵活的查询方法,可以快速的进行数据查询操作,查询条件可以用于读取.更新和删除等操作,主要涉及到 ...