1583
来源:互联网 发布:如何评价食草家族 知乎 编辑:程序博客网 时间:2024/06/10 23:15
紫书上的题,这道题不能用普通的 for 循环做,否则肯定超时,正如紫书上的说,要先打表,先把所有的结果存起来,然后在主函数中直接运用,这样可以减少运行时间;
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;#define max 100005int sum[max];int main(){ int n; memset(sum,0,sizeof(sum)); for(int k=1;k<max;k++){ int x=k,y=k; while(x>0) {y+=x%10;x=x/10;} if(sum[y]==0||k<sum[y]) sum[y]=k; } cin>>n; while(n--){ int m;cin>>m; cout<<sum[m]<<endl; } return 0;}
0 0
- 1583
- UVA 1583
- UVA-1583
- UVA-1583
- UVa 1583
- uva 1583
- UVA 1583
- hdu 1583 DNA Assembly
- hdu 1583 DNA Assembly
- Algorithm Practice for 1583
- UVA-1583 - Digit Generator
- UVa 1583 Digit Generator
- UVa 1583 - Digit Generator
- UVA 1583 - Digit Generator
- UVa 1583 Digit Generator
- UVa 1583打表
- UVa 1583 - Digit Generator
- UVa-1583Digit Generator
- 蓝桥杯 操作格子(线段树例题)
- ASP.NET C#学习二(数据库开发)
- h5本地存储的sessionStorage和localStorage
- Keras Tensorflow TF_NewStatus错误修改
- Java基础——常量
- 1583
- UML类图画法及其之间的几种关系
- test
- IDEA远程调试的
- 算法导论 快速排序
- 安卓databinding介绍
- A
- 宏观结构分析之语篇模式视角
- struts2 if标签用法实例