题目链接:JiLi Number
题目大意:现在有一个范围n,现在需要你去统计这个范围内的吉利数,吉利数的定义是,这个当统计到这个数的时候数位1的数量刚好等于当前统计到的这个数字时,那么他就是吉利数,统计贡献
题目思路:题目给的数据有一组是边界条件83个,打个表,统计到1e10,然后打完了82个,就好了,因为在我们可以发现1增加的速度在最后会远远超过本身的数字,所以打好边界的表就好了
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
ll n;
ll a[84] = {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,
1111111110};
char str[105];
while(~scanf("%s",str)){
if(strlen(str) >= 11) {printf("83 1111111110\n");continue;}
ll ans = 0;
for(ll i = 0;i < strlen(str);i++) ans = ans*10+str[i]-'0';
for(ll i = 0;i < 84;i++) if(ans < a[i]) {printf("%lld %lld\n",i,a[i-1]);break;}
}
return 0;
}

本文介绍了一种用于查找吉利数的高效算法。吉利数是指在数位1的数量等于该数本身时的数字。文章通过预计算边界条件并使用查找表的方法,在大范围内快速确定吉利数的存在。适用于竞赛编程和算法挑战。
872

被折叠的 条评论
为什么被折叠?



