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 |
这题不需用64位整型。用long就行了,最重要的是找规律(附代码):#include"iostream" using namespace std; int main() { int n; scanf("%d",&n); while(n--) { long x,y; int i,temp; scanf("%d%d",&x,&y); if(y-x-2<=0) { cout<<y-x<<endl; continue; } temp=y-x; for(i=1;;i++) if(temp==i*i) { cout<<2*i-1<<endl; break; } else if(temp>i*i&&temp<=i*(i+1)) { cout<<2*i<<endl; break; } else if(temp>i*(i+1)&&temp<=(i+1)*(i+1)) { cout<<2*i+1<<endl; break; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator