您的位置:首页 > Web前端

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
1
output
19
input
2
output
28
NoteThe 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: