题意:问有如下规律的数列的第n项是啥:
11212312341234512345612345671234567812345678912345678910123456789101112345678910
解法:每段连续数字为一组,算每组序列的长度,累加直到超过n,说明n在前一组连续数字内,枚举组内数字,累加长度直到超过n,说明n在前一数字中,找出这一数位输出。
总的来说就是一有点恶心的模拟……最后我想说……
注意longlong
对……每次都记不住……_(:з」∠)_
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
int main()//变量名起的变幻莫测不忍吐槽嗷
{
int T;
scanf("%d", &T);
while(T--)
{
LL n;
scanf("%I64d", &n);
LL sum = 0, x = 0, i = 1;
for(; n > sum; i++)
{
x += (LL)log10(i + 0.5) + 1;
sum += x;
}
i--;
LL tmp = n - (sum - x);
LL sum1 = 0;
for(LL j = 1; j <= i; j++)
{
sum1 += (LL)log10(j + 0.5) + 1;
if(sum1 >= tmp)
{
if(sum1 > tmp)
sum1 -= (LL)log10(j + 0.5) + 1;
LL ttmp = tmp - sum1;
vector <int> ans;
LL x1 = j;
while(x1)
{
ans.push_back(x1 % 10);
x1 /= 10;
}
if(ttmp == 0) ttmp = ans.size();
printf("%d\n", ans[ans.size() - ttmp]);
break;
}
}
}
return 0;
}