uva 1583 Digit Generator
来源:互联网 发布:酷狗音乐mac版 编辑:程序博客网 时间:2024/06/08 12:36
点击打开链接
输入一个数,输出其最小生成元。刚开始看时一脸懵逼,想要对于给定的每一个数倒着找,但是那样没法写。
字数上用的打表,最终查表直接输出即可,一定要学会这种方法,有时能够很有效的避免TLE并且很简洁。
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#define maxn 100001int main(){ int a[maxn],k,t; memset(a,0,sizeof(a)); for(int i = 1;i < maxn;i++)//最好的方法:一次性枚举,最后查表即可; { int m = i,n = i; while(n) { m += n%10; n /= 10; } if(a[m] == 0 || i < a[m]) a[m] = i;//a[m] != m 别搞反; } scanf("%d",&t); while(t--) { scanf("%d",&k); printf("%d\n",a[k]); } 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
- IP组播基础知识
- io性能专题分析--持续跟新
- Activity应用及启动模式
- Android逐帧动画的简单使用-语音播放效果的实现
- Xutils——BitmapUtils单例实现
- uva 1583 Digit Generator
- IPV6基础知识
- Spring Boot 下配置SpringDataJpa
- 实训周报1-AlexNet论文全解读
- 如何安装配置Redis
- iOS的UIView和CALayer
- [仙人掌直径 单调队列 DP] BZOJ 1023 [SHOI2008]cactus仙人掌图
- mysql
- iOS GPUImage之GPUImageFilterGroup组合滤镜(5)