Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这题不需用64位整型。用long就行了,最重要的是找规律(附代码):

Posted by 0810311106 at 2009-09-26 20:42:40 on Problem 2590
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator