UVa 1583打表
来源:互联网 发布:同城网络超市 编辑:程序博客网 时间:2024/05/22 12:44
背景:1--TLE:超时,没有考虑到时间复杂度,开始对每一个数都从1开始到99999,这样就是O(t*key)这样20组大数就可以超时。2--WA:3--WA都是把数字误以为最多4位了,其实是五位!!!。
思路:找出i(从1到100000)产生的数n,i是n的生成元,由于最多5位数字相加,所以n-i<50.对于每个要找生成元的数t,如果t大于50,只需搜索(t-50,t)。
学习:1.对于所有情况最多10万级别的可以打表。
#include<stdio.h>int str[99999];int main(void){ str[0]=0; for(int i=1;i<99999;i++){ int temp=i; str[i]=i; for(int j=0;j<5;j++){ str[i]+=temp%10; temp/=10; } } int t; scanf("%d",&t); while(t--){ int key,judege=0; scanf("%d",&key); for(int i=1;i<99999;i++){ if(i==1){ if(key>50) i=key-50; } if(str[i]==key){ judege=1; printf("%d\n",i); break; } } if(!judege) printf("0\n"); }return 0; }
0 0
- UVa 1583打表
- UVA 1583 打表 数论
- UVa 1583 Digit Generator(枚举+打表)
- UVA 1583 Digit Generator(最小生成元+打表)
- UVA 10396 - Vampire Numbers(暴力打表)
- uva 10916 Factstone Benchmark(打表)
- Uva 305 Joseph(数学+打表)
- UVa 1225 - Digit Counting【打表】
- UVA 10200 (欧拉定理打表)
- 【UVa】10200 - Prime Time(打表)
- 素数打表 UVA 10200 - Prime Time
- UVa - 1225 - Digit Counting(打表计算)
- uva 305 Joseph(约瑟夫环解+打表)
- UVA 305 Joseph (约瑟夫环 打表)
- UVA 10706 Number Sequence (找规律 + 打表 + 查找)
- UVa 568 Just the Facts (数论&打表&不打表)
- UVA 10169 - Urn-ball Probabilities !(概率 打表)
- UVA 1482 - Playing With Stones(SG打表规律)
- 关于面试你不知道的几点
- 动态规划算法和贪心算法的比较
- Spring——IOC(二)
- iOS开发- 项目中常用的svn命令
- 记录一个小汇编加法
- UVa 1583打表
- loop设备及losetup命令介绍
- 浅谈技术管理
- 类型修饰符const关键字
- Eclipse中绑定android sdk源码
- SpringMVC+Shiro权限管理
- Redhat Linux Server 报未注册的错误
- VIM,每天学习一点点
- Android recovery 下使用 updater-script 自制升级包