UVa 1583 - Digit Generator
A+A的每一位的数字的和=B
问你每一个B对应 的最小的A 是多少
不然输出0;
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int N=;
int ans[*N],tmp,cnt,n,t;
void fuc(){
memset(ans,,sizeof(ans));
for(int i=;i<=N;i++){
tmp=i; cnt=;
while(tmp>){
cnt+=tmp%;
tmp/=;
}
cnt+=i;
if(ans[cnt]==) ans[cnt]=i;
}
}
int main()
{
fuc();
scanf("%d",&t);
while(t--){
scanf("%d",&n);
printf("%d\n",ans[n]);
}
}
UVa 1583 - Digit Generator的更多相关文章
- UVa 1583 Digit Generator --- 水题+打表
UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...
- UVa 1583 Digit Generator(数学)
题意 假设a加上a全部数位上的数等于b时 a称为b的generator 求给定数的最小generator 给的数n是小于100,000的 考虑到全部数位和最大的数99,999的数位和也才45 ...
- 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 ...
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
- Digit Generator(水)
题目链接:http://acm.tju.edu.cn/toj/showp2502.html2502. Digit Generator Time Limit: 1.0 Seconds Memor ...
- [C++]最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n( ...
- 【UVA 1583】Digit Generator
题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...
随机推荐
- css系列教程--margin padding column(完结)
margin/margin-left/margin-right/margin-top/margin-bottom设置边距属性margin:0;--所有外边距0margin:0 1px;--margin ...
- ExtJs4.0入门错误
当在eclipse中的web工程中增加了extjs4,出现An internal error occurred during: "Building workspace". Java ...
- c语言中的经典算法
c语言经典排序以及查找方法 冒泡排序 #include <stdio.h> int main() { int i, j, t, a[11]; /*定义变量及数组为基本整型*/ printf ...
- java替换字符串和用indexof查找字符
java自带替换 String s="hlz_and_hourui哈哈"; String new_S=s.replaceAll("哈", "笑毛&qu ...
- GridView事件DataBinding,DataBound,RowCreated,RowDataBound区别及执行顺序分析
严格的说,DataBinding,DataBound并不是GridView特有的事件,其他的控件诸如ListBox等也有DataBinding,DataBound事件. DataBinding事件MS ...
- hadoop高可用集群搭建小结
hadoop高可用集群搭建小结1.Zookeeper集群搭建2.格式化Zookeeper集群 (注:在Zookeeper集群建立hadoop-ha,amenode的元数据)3.开启Journalmno ...
- input添加邮箱的时候自动显示后缀
1.HTML代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- Loader之一:基本原理
参考APIDEMO及http://developer.android.com/guide/components/loaders.html#app 1.Introduced in Android 3.0 ...
- FullScreenFragment Code
package com.dexode.fragment; import android.annotation.TargetApi; import android.app.Activity; impor ...
- 'ManyRelatedManager' object is not iterable
先看下面的代码: class Worker(models.Model): departments = moels.ManyToManyField(Department, verbose_name=u& ...