题意:在不超过N的正整数中,如果前x个数每个数中1的数量和为x,则x为JiLi Number,求不超过N的最大的JiLi Number
分析:给的样例中100000000000,比它大的数增加数字1的个数的速率比递增1的速率大,不会再存在JiLi Number了。而它对应的数是1111111110,所以打表1e10即可,发现不超过82的数可以在有限的时间里打出来。
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 210;
const int INF = 120;
typedef long long ll;
ll r[110] = {
0,
1,
199981,
199982,
199983,
199984,
199985,
199986,
199987,
199988,
199989,
199990,
200000,
200001,
1599981,
1599982,
1599983,
1599984,
1599985,
1599986,
1599987,
1599988,
1599989,
1599990,
2600000,
2600001,
13199998,
35000000,
35000001,
35199981,
35199982,
35199983,
35199984,
35199985,
35199986,
35199987,
35199988,
35199989,
35199990,
35200000,
35200001,
117463825,
500000000,
500000001,
500199981,
500199982,
500199983,
500199984,
500199985,
500199986,
500199987,
500199988,
500199989,
500199990,
500200000,
500200001,
501599981,
501599982,
501599983,
501599984,
501599985,
501599986,
501599987,
501599988,
501599989,
501599990,
502600000,
502600001,
513199998,
535000000,
535000001,
535199981,
535199982,
535199983,
535199984,
535199985,
535199986,
535199987,
535199988,
535199989,
535199990,
535200000,
535200001,
1111111110LL};
char s[110];
int cal_num(ll x)
{
int res = 0;
while(x)
{
if(x % 10 == 1)res++;
x /= 10;
}
return res;
}
void dabiao()
{
int cnt = 1;
ll ans = 0,ans1 = 0;
while(cnt <= 83)
{
ans++;
ans1 += cal_num(ans);
if(ans == ans1)
{
r[cnt++] = ans;
cout<<ans<<endl;
}
}
}
void test()
{
for(int i = 1; i <= 83; i++)
{
cout<<r[i]<<endl;
}
}
int main()
{
//dabiao();
// test();
while(~scanf("%s",s))
{
int len = strlen(s);
if(len > 10)
printf("83 1111111110\n");
else
{
ll ans = 0;
for(int i = 0; i < len; i++)
ans = ans * 10 + s[i] - '0';
if(ans >= 1111111110LL)
{
printf("83 1111111110\n");
}
else
{
for(int i = 1; i <= 83; i++)
{
// cout<<r[i]<<" "<<ans<<endl;
if(r[i] > ans)
{
printf("%d %lld\n",i - 1,r[i - 1]);
break;
}
}
}
}
}
return 0;
}