Problem K. JiLi Number
Description
Driver Ji likes the digit "1". Hehas an accumulator which shows the sum of input number. He lists all ofpositive number no more than N and starts counting from one, two, three...Everytime he counts a number he will add the number of digit "1" in thisnumber to accumulator at the same time. The amazing thing happens! At sometimes, when he finishes counting a number X, the number which on theaccumulator is X exactly, he will regard X as "JiLi Number" whichmeans lucky number. Now he wants to know the number of "JiLi Numbers"and the biggest "JiLi Number" no more than N.
Input
There are several test cases and the eachtest case is a line contains an positive integer N.(1<N≤10100)
Output
For each test case, output two integerswhich donates the number of "JiLi Numbers" and the biggest "JiLiNumber".
Sample Input
1
100000000000
Sample Output
1 1
83 1111111110
通过暴力求解,我们可以发现JiLi Number一共只有83个。所以可以打表。
Code:
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
long long ch[100];
char c[100];
int main()
{
ch[1]=1;
ch[2]=199981;
ch[3]=199982;
ch[4]=199983;
ch[5]=199984;
ch[6]=199985;
ch[7]=199986;
ch[8]=199987;
ch[9]=199988;
ch[10]=199989;
ch[11]=199990;
ch[12]=200000;
ch[13]=200001;
ch[14]=1599981;
ch[15]=1599982;
ch[16]=1599983;
ch[17]=1599984;
ch[18]=1599985;
ch[19]=1599986;
ch[20]=1599987;
ch[21]=1599988;
ch[22]=1599989;
ch[23]=1599990;
ch[24]=2600000;
ch[25]=2600001;
ch[26]=13199998;
ch[27]=35000000;
ch[28]=35000001;
ch[29]=35199981;
ch[30]=35199982;
ch[31]=35199983;
ch[32]=35199984;
ch[33]=35199985;
ch[34]=35199986;
ch[35]=35199987;
ch[36]=35199988;
ch[37]=35199989;
ch[38]=35199990;
ch[39]=35200000;
ch[40]=35200001;
ch[41]=117463825;
ch[42]=500000000;
ch[43]=500000001;
ch[44]=500199981;
ch[45]=500199982;
ch[46]=500199983;
ch[47]=500199984;
ch[48]=500199985;
ch[49]=500199986;
ch[50]=500199987;
ch[51]=500199988;
ch[52]=500199989;
ch[53]=500199990;
ch[54]=500200000;
ch[55]=500200001;
ch[56]=501599981;
ch[57]=501599982;
ch[58]=501599983;
ch[59]=501599984;
ch[60]=501599985;
ch[61]=501599986;
ch[62]=501599987;
ch[63]=501599988;
ch[64]=501599989;
ch[65]=501599990;
ch[66]=502600000;
ch[67]=502600001;
ch[68]=513199998;
ch[69]=535000000;
ch[70]=535000001;
ch[71]=535199981;
ch[72]=535199982;
ch[73]=535199983;
ch[74]=535199984;
ch[75]=535199985;
ch[76]=535199986;
ch[77]=535199987;
ch[78]=535199988;
ch[79]=535199989;
ch[80]=535199990;
ch[81]=535200000;
ch[82]=535200001;
ch[83]=1111111110;
while (scanf("%s",c)!=EOF)
{
int l=1,r=83,ans=-1;
int ll=strlen(c);
if (ll>10)
{
printf("83 1111111110\n");
continue;
}
long long num=0;
for (int i=0;i<ll;i++) num=num*10+c[i]-'0';
while (l<=r)
{
int mid=(l+r)>>1;
if (num<ch[mid]) r=mid-1;
else l=mid+1,ans=mid;
}
printf("%d %lld\n",ans,ch[ans]);
}
return 0;
}
标签:ch,int,Number,number,JiLi,83,he From: https://blog.51cto.com/u_15888102/5878353