uva 1583
枚举1~100000把所有数的最小generators记录下来,直接查表即可。
AC代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100000+50;
int ans[maxn];
int get(int a){
int b=a;
while(b>0){
a+=b%10;
b/=10;
}
return a;
}
void solve(){
memset(ans,0,sizeof(ans));
for(int i=0;i<=100000;++i){
int p=get(i);
if(ans[p]==0) ans[p]=i;
}
}
int main(){
solve();
int T,n;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
printf("%d\n",ans[n]);
}
return 0;
}
如有不当之处欢迎指出!
uva 1583的更多相关文章
- UVa 1583 Digit Generator --- 水题+打表
UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...
- 【UVA 1583】Digit Generator
题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...
- 生成元(Digit Generator ,ACM/ICPC Seoul 2005 ,UVa 1583)
生成元:如果 x 加上 x 各个数字之和得到y,则说x是y的生成元. n(1<=n<=100000),求最小生成元,无解输出0. 例如:n=216 , 解是:198 198+1+9+8=2 ...
- UVa 1583 Digit Generator(数学)
题意 假设a加上a全部数位上的数等于b时 a称为b的generator 求给定数的最小generator 给的数n是小于100,000的 考虑到全部数位和最大的数99,999的数位和也才45 ...
- UVa 1583 - Digit Generator
A+A的每一位的数字的和=B 问你每一个B对应 的最小的A 是多少 不然输出0: #include <cstdio> #include <iostream> #include ...
- 生成元(Digit Generator,ACM/ICPC Seoul 2005,UVa 1583)
#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int t, n, a, ...
- UVa 1583 - Digit Generator 解题报告 - C语言
1.题目大意 如果a加上a的各个数字之和得到b,则说a是b的生成元.给出n其中$1\le n\le 100000$,求其最小生成元,若没有解则输出0. 2.思路 使用打表的方法打出各个数字a对应的b, ...
- uva 1583 Digit Generator(Uva-1583)
题目不再写入了,vj:https://vjudge.net/problem/UVA-1583#author=0 主要讲的是找一个数的小于它的一个数,小于它的那个数每一位加起来再加上那个数就会等于原来的 ...
- UVa 1583 Digit Generator WA
#include<stdio.h> int main() { long int n,i,s=0; while(scanf("%d",&n)!=EOF) { in ...
随机推荐
- Apache Shiro java安全框架
什么是Apache Shiro? Apache Shiro(发音为“shee-roh”,日语“堡垒(Castle)”的意思)是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理功能,可为 ...
- Mybatis (一)
1 DAO层框架 框架:是一种整体的解决方案. 1.1 JDBC的步骤 1.2 Hibernate执行的步骤 1.3 MyBaits 2 Mybatis简介 Mybatis是支持定制化SQL.存储过程 ...
- awk 里的substr()
awk 里的substr函数用法举例: 要截取要截取的内容1: F115!16201!1174113017250745 10.86.96.41 211.140.16.1 200703180718F12 ...
- zabbix3.2_yum官方文档centos 7版
Installation from packages 1 Repository installation 2 Server installation with MySQL database 3 Ser ...
- 【转】CentOS 6.3(x86_32)下安装Oracle 10g R2
一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal / ...
- 认识Webpack
认识Webpack 网上已经有不少Webpack教程入门教程了. 本文记录了我以我的方式方法.思路认识了解Webpack.从官方的Tutorial入手,不断提出问题.解决,一步一步认识Webpac ...
- GitHub For Beginners: Commit, Push And Go
In Part 1 of this two-part GitHub tutorial, we examined the main uses for GitHub and bega5n the proc ...
- 自定义Func模块
自定义Func模块 (1)自定义模块步骤 (2)生成模块 [root@controller modules]# cd /usr/lib/python2.7/site-packages/func/min ...
- DFS实现排列组合
所谓排列,是指从给定的元素序列中依次取出元素,需要考虑取出顺序.比如,取出元素3, 5,因取出顺序的不同,则形成的序列{3, 5}与{5, 3}是不同的排列序列.对于长度为n的元素序列取出k个元素,则 ...
- c#监测电脑状态
public class DeviceMonitor { static readonly PerformanceCounter cpuCounter = new PerformanceCounter( ...