首页 > 代码库 > Poj 1019

Poj 1019

传送门:http://poj.org/problem?id=1019

主要是找数学规律

然后用好pow和log函数,由于数组过大,数组的类型用unsigned

 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 
 5 int t;
 6 int k;
 7 int n;
 8 unsigned a[31269];
 9 int m;
10 
11 int main(){
12     cin>>t;
13     a[0]=0;
14     for(int i=1;i<31269;i++){
15         a[i]=a[i-1]+int(log10(double(i)))+1;
16     }//打表
17     while(t--){
18         cin>>k;
19         n=1;
20         while(a[n]<k){
21             k-=a[n];
22             n++;
23         }
24         m=1;
25         int q=int(log10(double(m)))+1;
26         while(q<k){
27             k-=q;
28             m++;
29             q=int(log10(double(m)))+1;
30         }
31         cout<<m/int(pow(double(10),double(q-k)))%10<<endl;
32 
33     }
34 }

 

Poj 1019