POJ1019--5 2 1 36 9 80 69 85



提示:  int  x(n的位数)=(int)log10(n)+1;


Source Code
Problem: 1019		User: 14110103069
Memory: 964K		Time: 16MS
Language: G++		Result: Accepted

    Source Code

    #include <iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<map>
    #include<set>
    #include<string>
    #include<algorithm>
    #define LL long long
    #define uint unsigned
    using namespace std;
    const int N = 31270;
    uint a[N];
    uint sum[N];
    uint solve(uint n)
    {
        int x=lower_bound(sum,sum+N,n)-sum;
        uint pos=n-sum[x-1];
        uint len=0;
        uint i;
        for( i=1;len<pos;i++)
        {
            len+=(int)log10((double)i)+1;
        }
        return (i-1)/(int)pow(10,len-pos)%10;
    }
    int main()
    {
        //freopen("out.txt","w+",stdout);
        for(int i=1;i<N;i++)
        {
            a[i]=a[i-1]+(int)log10((double) i)+1;
            sum[i]=sum[i-1]+a[i];
        }
        uint n;
        int t;
        while(cin>>t)
        {
            while(t--)
         {
             cin>>n;
             cout<<solve(n)<<endl;
         }
        }
        return 0;
    }


你可能感兴趣的:(POJ1019--5 2 1 36 9 80 69 85)