题意:
求数字11212312341234512345612345671234567812345678912345678910123456789101112345678910111212345678910111213...的第i位是几?
数位dp打表+二分+暴力模拟
0msAC哦!暴力美学!
1 #include <set> 2 #include <map> 3 #include <cmath> 4 #include <queue> 5 #include <vector> 6 #include <cstdio> 7 #include <cstdlib> 8 #include <cstring> 9 #include <iostream> 10 #include <algorithm> 11 using namespace std; 12 int a[31268],f[31268],b[11],i_b; 13 int digit(int x) { 14 if(x>999999999)return 10; 15 if(x>99999999)return 9; 16 if(x>9999999)return 8; 17 if(x>999999)return 7; 18 if(x>99999)return 6; 19 if(x>9999)return 5; 20 if(x>999)return 4; 21 if(x>99)return 3; 22 if(x>9)return 2; 23 return 1; 24 } 25 int main() { 26 int i,j,k; 27 for(i=1; i<=31267; i++) { 28 for(j=i; j>=1; j--) 29 if(f[j]) {a[i]+=f[j];break;} 30 else a[i]+=digit(j); 31 f[i]=a[i]; 32 a[i]+=a[i-1]; 33 }//a[31267]=2147378477 34 int T,I; 35 for(scanf("%d",&T); T--;) { 36 scanf("%d",&I); 37 int l=1,r=31267; 38 while(r-l>1) { 39 int mid=(l+r)/2; 40 if(I>a[mid])l=mid; 41 else if(I==a[mid])l=mid,r=mid; 42 else r=mid; 43 } 44 int cnt=I-a[l],num,ans; 45 if(!cnt) {cout<<l%10<<endl;continue;} 46 for(i=l+1; cnt; i++) 47 for(j=1; j<=i && cnt; j++) 48 for(num=j,ans=0,k=j; k && cnt; k/=10,cnt--,ans++); 49 for(i_b=0,k=num; k ; b[++i_b]=k%10,k/=10); 50 cout<<b[i_b-ans+1]<<endl; 51 } 52 return 0; 53 }