HDU4722Good Numbers热身赛2 1007题(思维题 不用数位dp照样可以做的)
来源:互联网 发布:西门子plc的编程技巧 编辑:程序博客网 时间:2024/05/22 21:19
Good Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 268 Accepted Submission(s): 90
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.
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).
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
21 101 20
Sample Output
Case #1: 0Case #2: 1HintThe answer maybe very large, we recommend you to use long long instead of int.
Source
2013 ACM/ICPC Asia Regional Online —— Warmup2
题目大意:给你a,b两个数(a<=b),问你a~b满足各个数位相加整除10的个数,含边界。
解题思路:说下我的总体思想吧。先枚举一下0~200内满足条件的值,0,19,28,37,46,55,64,73,82,91,109,118,127,136,145,154,163,172,181,190.规律应该很显然了,0~10中有一个,10~20中有一个。。。一次的每十个中必有一个。可以自己在纸上画一下,一个很大的数共有n位,前面n-1位的和是p而最后一位还没确定,最后一位可以取q=0~9,可以自己想一下结果肯定是(p+q)%10,而模上10以后的结果必是从0~9所以每十个里面有一个。 下面的就好办了。问你a~b满足条件的个数,就先求边界c~d(c>=a且最小的满足条件的数,d<=b且最小的满足条件的数)。不过个数为0需要特殊判断一下。详见代码。
题目地址:Good Numbers
AC代码:
#include<iostream>#include<cstring>#include<string>#include<cstdio>#include<cmath>#include<algorithm>using namespace std;char a[12][12];int is(__int64 x){ int ans=0; while(x) { ans+=x%10; x/=10; } if(ans%10==0) return 1; return 0;}int main(){ int tes; __int64 res; __int64 a,b; scanf("%d",&tes); int cas=0; while(tes--) { scanf("%I64d%I64d",&a,&b); while(!is(a)) //先找到>=a的最小数位相加整除10的数 a++; while(!is(b)) //先找到<=b的最大数位相加整除10的数 b--; if(a>b) res=0; else //即为a<=b的时候再用相减的方法,保险起见 res=b/10-a/10+1; //每10个里面有一个 printf("Case #%d: %I64d\n",++cas,res); } return 0;}/*2101 101 2032 4332 4691 1090 1001 100*///46MS 232K
- HDU4722Good Numbers热身赛2 1007题(思维题 不用数位dp照样可以做的)
- hdu4722Good Numbers数位dp
- CodeForces 55D. Beautiful numbers (思维+数位DP)
- HDU4722Good Numbers 找规律
- codeforce 55 D. Beautiful numbers(数位dp,好题)
- POJ-3252 Round Numbers (数位dp 好题)
- 【数位DP】SPOJ10606Balanced Numbers
- 【数位DP】SPOJ10606Balanced Numbers
- poj3252Round Numbers【数位dp】
- 数位dp Beautiful numbers
- SPOJ10606Balanced Numbers(数位DP)
- 数位dp, Beautiful numbers
- POJ3252Round Numbers(数位DP)
- Good Numbers (数位DP)
- 数位DP 思维起步
- 不用光驱和软驱照样可以装系统
- 不用asp.net MVC,用WebForm照样可以实现MVC
- 无线路由连接(不用连接WAN照样可以上网)
- MYSQL数据库自增主键的重要性
- php和XML
- XMPP协议实现原理介绍
- H面试程序(7):去掉字符串中重复的数
- 在做Android分享时遇到的一些问题
- HDU4722Good Numbers热身赛2 1007题(思维题 不用数位dp照样可以做的)
- OpenCV 第八章 cvConvertHull2 ( 二 )
- sql中防止记录重复的方法
- boost
- 在BackGroundWorker中使用ArcGIS组件
- python中cx_Oracle的操作
- MODELISM 仿真遇到glbl问题
- 如何打包供一键安装及越狱设备使用的ipa
- CCAnimation类 参考