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 |
那位高手帮我看一下我的程序为什么WA?谢了。#include<iostream> using namespace std; __int64 p,r,k1,k2,n=0,s[20],q[15],k,kbefore; int s_i,q_i; int sum(__int64 k,__int64 *s,int s_i,int sign) { k1=0; __int64 temp,temp1,begin1,begin,end,mid; while(k1<k) { temp=(s[s_i+1]-s[s_i])*s_i; if(k1+temp<k) {k1+=temp; s_i++;} else break; } if(k1+temp==k) { if(sign==0)temp1=(s[s_i+1]-1)*(s[s_i+1]-1); else temp1=s[s_i+1]-1; p=temp1%10; k1=k; } else { begin=s[s_i],end=s[s_i+1]-1,begin1=begin; while(begin<=end) { mid=(begin+end)/2; if((mid-begin1+1)*s_i+k1>k) { if((mid-begin1)*s_i+k1<k) { if(sign==0)p=mid*mid; else p=mid; k1+=(mid-begin1+1)*s_i; break; } else end=mid-1; } else if((mid-begin1+1)*s_i+k1<k) { if((mid-begin1+2)*s_i+k1>k) { if(sign==0)p=(mid+1)*(mid+1); else p=mid+1; k1+=(mid-begin1+2)*s_i; break; } else begin=mid+1; } else { if(sign==0)p=mid*mid; else p=mid; k=k1; break; } } } for(int i=0;i<k1-k;i++) p/=10; return p%10; } int sum1(__int64 k) { int Sum=sum(k,s,1,0)+sum(k,q,1,1); return Sum; } int Inc(__int64 k) { int m=1,t=1; while(t) { int temp=sum1(k+m); while(temp>9) { m++; temp=sum1(k+m); } t=0; if(temp==9&&sum1(k+m+1)>9) m+=2; } while(m>1) { t=(t+sum1(k+m-1))/10; m--; } return t; } int main() { s[1]=1,s[2]=4,s[3]=10,s[4]=32,s[5]=100,s[6]=317,s[7]=1000,s[8]=3163,s[9]=10000,s[10]=31623; s[11]=100000,s[12]=316228,s[13]=1000000,s[14]=3162278,s[15]=10000000,s[16]=31622777,s[17]=100000000; s[18]=316227767,s[19]=1000000000; q[1]=1,q[2]=10,q[3]=100,q[4]=1000,q[5]=10000,q[6]=100000,q[7]=1000000,q[8]=10000000,q[9]=100000000; q[10]=1000000000,q[11]=10000000000,q[12]=100000000000,q[13]=1000000000000,q[14]=10000000000000; scanf("%Id",&k); while(k) { cout<<(sum1(k)+Inc(k))%10; cout<<endl; scanf("%Id",&k); } return 0; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator