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.
题意:求第k大的一个数,使得其满足各数位之和等于10。
打表模拟即可
#include <bits/stdc++.h>
using namespace std;
int num[11000];
int main()
{
int cnt=0;
int sum=10,jw=0;
while (cnt<10000){
int jwval=0,tmp=jw;
while (tmp){
jwval+=tmp%10;
tmp/=10;
}
for (int i=0;i<=9;i++){
if (sum-i-jwval<10&&sum-i-jwval>=0)
num[cnt++]=(sum-i-jwval)+i*10+jw*100;
}
jw++;
}
int k;
while (cin>>k){
cout<<num[k-1]<<endl;
}
return 0;
}