UVa1583-Digit Generator
来源:互联网 发布:php的exec函数 编辑:程序博客网 时间:2024/05/22 01:48
UVa1583-Digit Generator
思路:
打表法,因为每次重新算很费时间,所以预处理一下,从1开始算把算出来的n放到以n为下标的数组中,这样计算的复杂度就是线性的。
代码:
#include <bits/stdc++.h>#define MAX 100005using namespace std;int a[MAX];int suan(int n){ int ans=n; while(ans) { n+=ans%10; ans/=10; } return n;}int main(){ int n,ans; cin>>n; for(int i=0;i<MAX;i++) { if(!a[suan(i)])a[suan(i)]=i; } while(n--) { cin>>ans; cout<<a[ans]<<endl; } return 0;}
阅读全文
0 0
- UVa1583 - Digit Generator
- UVA1583 - Digit Generator
- uva1583 - Digit Generator
- uva1583-digit generator
- UVA1583 UVALive3355 Digit Generator
- UVA1583 - Digit Generator
- UVa1583-Digit Generator
- Digit Generator—UVa1583
- UVa1583——Digit Generator
- UVa1583 Digit Generator另一种解法
- UVA1583 - Digit Generator(生成元,打表)
- Digit Generator, ACM/ICPC Seoul 2005, UVa1583
- [Digit Generator, ACM/ICPC Seoul 2005, UVA1583]
- 生成元(Digit Generator,ACM/ICPC Seoul 2005, UVa1583)
- 生成元(Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
- uva1583 Digit Generator && uva1584 Circular Sequence(水)
- UVa1583 - Digit Generator 生成元 (java版本)
- 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
- 【HDU 1102】Constructing Roads(最小生成树)
- UVa1225-Digit Counting
- 僵尸、孤儿、守护进程
- jQuery遍历之children()方法
- 2017 暑假艾教集训 day3
- UVa1583-Digit Generator
- hdu--6077 Time To Get Up
- [随心译]2017.8.3-华硕推出售价$648的ZenFone AR,现已在Verizon接受预订
- LFS-Linux From Scratch学习笔记——简介与准备工作
- UVa1584-Circular Sequence
- UVa1585-Score
- jQuery遍历之find()方法
- cookie setMaxAge 无效
- HDU6075 Questionnaire 模拟