UVa 1583 - Digit Generator
来源:互联网 发布:miru隐形眼镜知乎 编辑:程序博客网 时间:2024/06/05 10:38
题目链接:点击打开链接
解题思路:打表。遍历1到1000000+10的数,注意已经存储过的不应该更新,不然无法保证是最小生成元。注意看sumDigit函数中的一个if判断。
代码:
#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int n;const int maxn = 1000000+10;int a[maxn];int sumDigit(int num){ int ans = 0; while(num) { ans += num%10; num /= 10; } return ans;}int main(){ memset(a, 0, sizeof(a)); for(int i = 0; i < maxn; i++) { int tmp = i + sumDigit(i); if(!a[tmp]) { a[tmp] = i; } } int n; while(scanf("%d", &n) == 1) { int num; for(int i = 0; i < n; i++) { scanf("%d", &num); printf("%d\n", a[num]); } } return 0;}
0 0
- UVA-1583 - Digit Generator
- UVa 1583 Digit Generator
- UVa 1583 - Digit Generator
- UVA 1583 - Digit Generator
- UVa 1583 Digit Generator
- UVa 1583 - Digit Generator
- UVa-1583Digit Generator
- 【Uva 1583】 Digit Generator
- UVA - 1583 Digit Generator
- Uva - 1583 - Digit Generator
- UVA - 1583 Digit Generator
- UVa 1583 - Digit Generator
- UVA 1583 Digit Generator
- UVa 1583 Digit Generator
- UVA - 1583 Digit Generator
- UVa 1583 - Digit Generator
- UVa 1583 - Digit Generator
- UVa 1583 - Digit Generator
- 面试的一些小经验
- BFS- 迷宫中的英雄
- eclipse快捷键
- 关于Java是传值还是传引用的笔记
- 发现自己
- UVa 1583 - Digit Generator
- 探索 ConcurrentHashMap 高并发性的实现机制
- Hibernate4映射总结(1)——XML配置
- StringTokenizer类的使用方法(Java)
- UI进阶——地图的使用
- 递归的小例子
- android唤醒屏幕并解锁
- 1037. 在霍格沃茨找零钱(20)
- java 中的遇到的问题1