其他分享
首页 > 其他分享> > poj 1019(字符串,数学推导,log10,pow)

poj 1019(字符串,数学推导,log10,pow)

作者:互联网

#include<iostream>
#include<cmath>
using namespace std;
const int maxn = 32768;
long long a[maxn],s[maxn];
void init(){
    s[0] = 0;
    a[1] = s[1] = 1;
    for(int i=2;i<maxn;i++){
        a[i] = a[i-1]+(int)log10((double)i)+1;
        s[i] = s[i-1]+a[i];
    }
}
int compute(int n){
    int i=1;
    while(s[i]<n){
        i++;
    }
    int pos = n-s[i-1];
    int len = 0;
    for(i=1;len<pos;i++){
        len += (int)log10((double)i)+1;
    }
    return (i-1)/(int)pow((double)10,(double)len-pos)%10; 
}
int main(){
    int n,i;
    init();
    cin>>n;
    while(n--){
        cin>>i;
        cout<<compute(i)<<endl;
    }
    return 0;
}

 

标签:32768,cout,int,pow,long,maxn,1019,poj,include
来源: https://www.cnblogs.com/stevenzrx/p/15057667.html