B. Perfect Number
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
We 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.
Input
A single line with a positive integer k (1 ≤ k ≤ 10 000).
Output
A single number, denoting the k-th smallest perfect integer.
Examples
input
1
output
19
input
2
output
28
Note
The first perfect integer is 19 and the second one is 28.
一开始看少了个0以为是1000,哇了一次。。。
因为是第k小的数我想到了第10000小那得多大啊,于是把数组开了一个天文数字的大小,后来发现数据范围和有多少个数完全不是一回事啊啊啊啊啊啊啊
#include<iostream>
#include<math.h>
using namespace std;
bool check(int a){
double c=0,b=0,A=a;
while(a){
c=c+a%10;
a/=10;
}
if(c==10)return true;
else return false;
}
int a[10050]={0};//就是这里一开始开到了a[1000000000]然后超内存了
int INT(){
int j=0;
for(int i=0;i<20000000;i++){
if(j>=10050)break;
if(check(i)){
a[j]=i;j++;
}
}
}
int main(){
INT();
int m;
cin>>m;
cout<<a[m-1];
return 0;
}