1#include <cstdio>2#include <cstring>3 4 using namespacestd;5 6 intsum[ -];7 //Sum[i] Indicates the maximum number of possible digits for a group with a mantissa of I8 voidInit ()9 {Tensum[0] =0; Onesum[1] =9; Asum[2] =189; -sum[3] =2889; -sum[4] =38889; thesum[5] =488889; -sum[6] =5888889; - } - + //Finds the number of digits in the number of digits that the last corresponding group number belongs to, and returns an integer. - intGet_bit (int&N) + { A for(inti =0; i<6; i++){ at if(n > Sum[i] && n <= sum[i+1]) - { -N-=Sum[i]; - returni+1; - } - } in return-1; - } to //returns the number of the corresponding number in this group of G + intGet_num_of_group (intg) - { the intt =Ten; * intK =1; $ intRET =0;Panax Notoginseng while(g >=t) { -RET + = t/Ten*9*K; theT *=Ten; +k++; A } theRET + = (g-t/Ten+1) *K; + returnret; - } $ $ intMain () - { - intT; the //Cout<<get_num_of_group (<<endl;) -scanf"%d", &T);Wuyi init (); the while(t--){ - intN; Wuscanf"%d", &n); - intGroup =1; About intCNT =1; $ //Group indicates the number of groups in which CNT indicates the number of numbers contained in the corresponding group - while(1){ - if(n <= CNT) Break; -N-=CNT; Agroup++; +CNT =Get_num_of_group (group); the } - //cout<< "group" <<group<< "" "<<n<<endl; $ intt =get_bit (n); the //cout<< "T" <<t<<endl; the intSt; the //St means starting from several numbers, such as St = 10, indicating that the last point belongs to the 10-99 range the if(T <0) st =1, t =1; - Else in { theSt =1; the for(intI=1; i<=t-1; i++) AboutSt *=Ten; the the } the //cout<< "St" <<st<<endl; + while(N >t) { -N-=T; thest++;Bayi } then = t +1-N; the intAns = st%Ten; - for(intI=1; I<=n; i++){ -Ans = st%Ten; theSt/=Ten; the } theprintf"%d\n", ans); the } - //cout<<9 + 2*90 + 3*900<<endl; the return 0; the}
POJ 1019 Math Problems