题解:P13672 [GCPC 2023] German Conference for Public Counting
furina_yyds · · 题解
题解:P13672 [GCPC 2023] German Conference for Public Counting
这题有点偏思维。
思路
对于给定的数
不难得出,
代码
#include<bits/stdc++.h>
using namespace std;
long long n, ans;
int wei(long long x){
int cnt = 0;
while(x){
x /= 10;
cnt++;
}
return cnt;
}
long long shu(int a, int b){
long long cnt = 0;
while(a--){
cnt = cnt * 10 + b;
}
return cnt;
}
int main(){
scanf("%lld", &n);
if(n < 10){
printf("%lld", n + 1);
return 0;
}
int w = wei(n), w10 = pow(10, w - 1), shou = n / w10, ans = 0;
if(n < shu(w, shou))shou--;
ans = shou * w + (10 - shou) * (w - 1);
printf("%d", ans);
return 0;
}