codeforces Perfect Number(暴力)
2018-01-31 22:48
239 查看
B. Perfect Numbertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer.InputA
4000
single line with a positive integer k (1 ≤ k ≤ 10 000).OutputA single number, denoting the k-th smallest perfect integer.Examplesinput
题意很简单求出第K个所有位数加起来和为10的数字暴力的同时计数数据为10000时对应的数字是10800100复杂度O(n),可以卡过#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define maxn 10800100
int juge(int a){
int i = 0,cnt = 0;
while(a > 0){
cnt += a%10;
a/=10;
}
return cnt==10?1:0;
}
int main()
{
int cnt=0,i,n;
scanf("%d",&n);
for(i = 9;i <= maxn;i++){//个位数不可能是完美数,其实应该直接从19开始打表
if(juge(i))
cnt++;
if(cnt == n)
break;
}
printf("%d",i);
return 0;
}
4000
single line with a positive integer k (1 ≤ k ≤ 10 000).OutputA single number, denoting the k-th smallest perfect integer.Examplesinput
1output
19input
2output
28NoteThe first perfect integer is 19 and the second one is 28.
题意很简单求出第K个所有位数加起来和为10的数字暴力的同时计数数据为10000时对应的数字是10800100复杂度O(n),可以卡过#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define maxn 10800100
int juge(int a){
int i = 0,cnt = 0;
while(a > 0){
cnt += a%10;
a/=10;
}
return cnt==10?1:0;
}
int main()
{
int cnt=0,i,n;
scanf("%d",&n);
for(i = 9;i <= maxn;i++){//个位数不可能是完美数,其实应该直接从19开始打表
if(juge(i))
cnt++;
if(cnt == n)
break;
}
printf("%d",i);
return 0;
}
相关文章推荐
- Educational Codeforces Round 39-E-Largest Beautiful Number(暴力)
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
- “Or" Game CodeForces - 578B (暴力)
- C - Colorful Graph CodeForces - 246D (暴力坑题)
- Codeforces Round #394 (Div. 2)C. Dasha and Password【暴力】
- Codeforces Round #427 (Div. 2) A. Key races B. The number on the board C. Star sky
- Codeforces Round #398(Div. 2)D. Cartons of milk【二分+暴力处理】
- Codeforces Gym 101138C Stickmen 暴力搜索+组合数
- Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)
- Educational Codeforces Round 4 B. HDD is Outdated Technology 暴力
- Codeforces Round #192 (Div. 1) B. Biridian Forest 暴力bfs
- Codeforces Round #415 (Div. 2) A B C 暴力 sort 规律
- Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力
- Educational Codeforces Round 23 C. Really Big Numbers 暴力
- Codeforces Gym 100342E Problem E. Minima 暴力
- Codeforces Round #322 (Div. 2) D. Three Logos(暴力)
- Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
- Codeforces Gym 100203G G - Good elements 暴力
- Codeforces Round #430 (Div. 2) C Ilya And The Tree SET暴力