Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
该怎么办,,输入七位数就死掉了,出不了结果,六位数中222222以下能过,,超过333333就死掉了,呜呜呜.........////////////////***************/ #include<iostream> #include<cmath> using namespace std; int length_d2(int n)//n位数集; { return ( floor(sqrt( (int)pow(10 ,n) -1 ) ) - ceil(sqrt((int)pow(10 ,n-1))) +1) *n; } int length_d1( int n) { return 9*(int)pow(10 ,n-1) * n; } int compute(int &m , int &d1, int &d2) { int res1=9,res2=0; int mid[2]; int first[2] = {0}; int len[2],x[2],res[2]; x[0]=x[1]=m; int tag[2]={0}; int token[2]={0};//纪录对应的j; for(int i = 1;;) { if(tag[0] == 0) { len[0] = length_d1(i); if(x[0] > len[0] ) x[0] -= len[0] ; else if(x[0] == len[0]) { res[0] = 9; tag[0] = 1; token[0] = i ; } else { tag[0] = 1; token[0] =i ; } } if(tag[1] == 0) { len[1]=length_d2(i); if(x[1] > len[1]) x[1] -= len[1]; else { tag[1] = 1 ; token[1] =i; } } if(tag[1] == 0 || tag[0] ==0) i++; if(tag[1] == 1 && tag[0] ==1) { mid[0]=x[0]+1 ; mid[1] =x[1]+1; if(res[0] != 9)//res[0] 处于i 位数集中; { int l=1; while( x[0] > token[0]) x[0] -= token[0],l++; int target = (int )pow(10 , token[0] -1) + l - 1; int temp=0; while(temp < token[0]-x[0]) target=target/10,temp++; res[0] = target% 10; } if(first[0] == 0) d1 = res[0] ,first[0] =1; int l = 1; while(x[1] > token[1]) x[1] -= token[1], l++; int target = ceil (sqrt( int (pow( 10, token[1]-1) ) ) ) + l -1;//原来的数,非平方数; target = target *target; int temp = 0; while(temp < token[1] - x[1]) target /= 10 , temp++; res[1] = target%10 ; if(first[1] != 0) { if(res[0] + res[1] != 9) { d1 += (res[0]+res[1])/10; cout<<(d1 + d2)%10<<endl; return 0; } else { x[0] = mid[0]; x[1] = mid[1]; tag[0] = tag[1] = 0; continue; } } if(first[1] == 0) d2 =res[1],first[1] = 1; x[0] = mid[0]; x[1] =mid[1]; tag[0]=tag[1]=0; } }//for return 0; } int main() { int m; while(cin>>m &&m != 0) { int d1 ,d2 ; compute(m ,d1 ,d2); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator