HDOJ 4608 I-number

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=4608

I-number

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3105    Accepted Submission(s): 1165

Problem Description

The I-number of x is defined to be an integer y, which satisfied the the conditions below:

1. y>x;

2. the sum of each digit of y(under base 10) is the multiple of 10;

3. among all integers that satisfy the two conditions above, y shouble be the minimum.

Given x, you‘re required to calculate the I-number of x.

Input

An integer T(T≤100) will exist in the first line of input, indicating the number of test cases.

The following T lines describe all the queries, each with a positive integer x. The length of x will not exceed 105.

Output

Output the I-number of x for each query.

Sample Input

1
202

Sample Output

208

Source

2013 Multi-University Training Contest 1

题意: 给一个正整数x ,要你求最小的y。 使得的y>x 且y的各个位数之和能被10整除。 x的程度不超过 105.

题解: 简单大数加法 .

#include<iostream>
#include<string>
#define maxn 100000+5
using namespace std;
string str;
int sum=0,t;
int calcbit(string &x)
{
	int s=0;
	for(int i=0;i<x.size();i++) s+=(x[i]-'0');
	return s;
}
void Add(string &x)
{
	string temp="";char ch;
	int num[maxn]={0},len=x.size();
	for(int i=0;i<len;i++)num[i]=(x[len-i-1]-'0');
	num[0]++;
	for(int i=0;i<len;i++){
		if(num[i]>9){
			num[i+1]+=num[i]/10;
			num[i]%=10;
		}
	}
	int i;
	for(i=len;i>0&&!num[i];)i--;
	for(;i>=0;i--)temp+=(num[i]+'0');
	len=temp.size();
	for(int i=0;i<=len/2;i++){
	ch=x[i];x[i]=x[len-i-1];x[len-i-1]=ch;
	}
	x=temp;
}
int main()
{
	cin.sync_with_stdio(false);
	cin>>t;
	while(t--)
	{
		cin>>str;
		Add(str);
		sum=calcbit(str);
		while(sum%10){
			Add(str);
			sum=calcbit(str);
		}
		cout<<str<<endl;
	}
	return 0;
}
时间: 2024-11-25 10:40:39

HDOJ 4608 I-number的相关文章

hdoj 1492 The number of divisors(约数) about Humble Numbers 【数论】【质因子分解 求和】

定理:一个正整数 n 可以用素因子唯一表示为 p1^r1 * p2^r2 * ... pk^rk (其中 pi 为素数) , 那么这个数的因子的个数就是,(r1+1)*(r2+1)*...*(rk+1). 理解:为什么是加1之后再相乘,因为一个数的的因子数至少为1和他自身,但因为r1,r2..可以为0,所以因子的个数为(r1+1)... 拓展一下: 定理1: 一个正整数 n 可以用素因子唯一表示为 p1^r1 * p2^r2 * ... pk^rk (其中 pi 为素数) , 那么这个数的因子的

水题 HDOJ 4727 The Number Off of FFF

题目传送门 1 /* 2 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <string> 9 #include <cmath> 10 using namespace std; 11 12 const in

hdoj.3826 Squarefree number

hdoj 3826 Squarefree number 考虑一个数能被完全平方数整除,当且仅当对其分解质因数以后,至少有一个质数的指数\(≥2\) 借用试除法分解质因数的思路,大于\(\sqrt[3]{N}\)的质因子至多只有一个.那么,大于 \(\sqrt[3]{N}\) 的质因数的平方整除 $N $ 的个数至多也只有一个,而且指数至多为 \(2\) ,因为指数再大或者再乘上一个等数量级的完全平方数都会超过 $ 10^{18} $ 的数据范围. 然后就筛出 \(\sqrt[3]{10^{18}

HDOJ Guess the number 3337【神题-抓取杭电后台输出数据】

Guess the number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7077    Accepted Submission(s): 1626 Problem Description AekdyCoin is the most powerful boy in the group ACM_DIY, whose signatur

HDOJ 4937 Lucky Number

当进制转换后所剩下的为数较少时(2位.3位),相应的base都比較大.能够用数学的方法计算出来. 预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算. . .. Lucky Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 521    Accepted Submission(s): 150 Probl

hdoj 2665 Kth number主席树裸

Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9417    Accepted Submission(s): 2938 Problem Description Give you a sequence and ask you the kth big number of a inteval. Input The fi

HDOJ 3948 The Number of Palindromes 后缀数组

后缀数组求有多少个不同的回文串 The Number of Palindromes Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1976    Accepted Submission(s): 690 Problem Description Now, you are given a string S. We want to kno

HDOJ 2665 Kth number

静态区间第K小....划分树裸题 Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5341    Accepted Submission(s): 1733 Problem Description Give you a sequence and ask you the kth big number of a int

如何运用同余定理求余数【hdoj 1212 Big Number【大数求余数】】

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5930    Accepted Submission(s): 4146 Problem Description As we know, Big Number is always troublesome. But it's really important in our