你妹,你妹,你妹,看起来很容易。其实容易理解错题意,特别是给出的两个样例更容易让人误解题意。。。
好了,其实核心算法就是计算从1到 i 这 i 个数字序列中的数字个数。然后就很简单了;
我的AC代码:
# include <string>
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# define INF 2147483647
# define DEBUG
long long cnt(long long n) {
long long re = n;
if(n >= 10) re += n - 9;
if (n >= 100) re += n - 99;
if (n >= 1000) re += n - 999;
if (n >= 10000) re += n - 9999;
if (n >= 100000) re += n - 99999;
if (n >= 1000000) re += n - 999999;
if (n >= 10000000) re += n - 9999999;
return re;
}
int main () {
long long t;
#ifdef DEBUG
#endif
for (scanf("%lld", &t); t; t --) {
long long n;
scanf ("%lld", &n);
long long i,j,
sum = 0;
for (i = 0; ; ++ i) {
sum += cnt(i);
if (sum + cnt(i + 1) >= n) {n -= sum; break;}
}
for (j = 1; j <= i + 1; ++ j) {
if (cnt(j) >= n) {n -= cnt(j - 1); break;}
}
char str[10];
sprintf(str, "%d", j);
printf ("%c\n", str[n - 1]);
}
return 0;
}