HDU 4722 Good Numbers(找规律)
2016-04-12 20:42
471 查看
hdu 4722
0-10 1
0-100 10
0-1000 100
0-990 99
0-992 100
0-997 100
基本规律为 n/10 + (1或0)
加1的情况为:n/10*10 到 n 有满足条件的 比如:997: 99 + (990到997是否有满足条件的,如果有则加1)
需要注意的是,比如 0 820 ,应该有83种而不是82种,因为820本身也满足。
参考博客:/article/6569422.html 感谢!
0-10 1
0-100 10
0-1000 100
0-990 99
0-992 100
0-997 100
基本规律为 n/10 + (1或0)
加1的情况为:n/10*10 到 n 有满足条件的 比如:997: 99 + (990到997是否有满足条件的,如果有则加1)
需要注意的是,比如 0 820 ,应该有83种而不是82种,因为820本身也满足。
参考博客:/article/6569422.html 感谢!
#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> using namespace std; long long cal(long long a) { if(a < 0) return 0; else if(a <= 10) return 1; long long cnta = a / 10; int l = a % 10; long long tmp = 0; while(a /= 10) { tmp += a % 10; } tmp %= 10; if(tmp != 0) { tmp = 10 - tmp; if(l >= tmp) cnta++; } else cnta++; return cnta; } int main() { int T; scanf("%d", &T); int i; for(i = 1; i <= T; i++) { long long a, b; scanf("%I64d %I64d", &a, &b); a = a - 1; long long cnta = cal(a); long long cntb = cal(b); printf("Case #%d: %I64d\n", i, cntb - cnta); } return 0; }
相关文章推荐
- Django ModelAdmin 中设置字段的默认值
- Kolmogorov–Smirnov test
- 30分钟配置好-Puppet: 强大的中心化配置管理系统
- Google Code Jam 2016 资格赛
- GoldenGate 配置extract,replicat进程自启动
- 推荐10个免费在线测试网页性能工具
- Polygonising a scalar field
- hihoCoder:403 Forbidden
- 【ZOJ3935 The 16th Zhejiang University Programming ContestI】【暴力 水题】2016 找寻triangular-hexagonal-leap y
- STL Algorithms in Action
- Goal: Psychology
- Ubuntu:GoldenDict 词典安装
- django日志logging 的配置以及处理
- 扫描线算法的论文《The Intersections for a Set of 2D Segments, and Testing Simple Polygons》的部分翻译
- golang操作文件
- 重构第27天 去除上帝类(Remove God Classes)
- golang获取程序运行路径
- 用Golang写一个搜索引擎(0x02)
- golang 版本的 crontab
- hdu 1847 Good Luck in CET-4 Everybody!