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

跟我的算法几乎一样,我也是WA。。= =

Posted by tbziy2 at 2011-05-25 01:04:35 on Problem 1061 and last updated at 2011-05-25 10:04:24
In Reply To:大哥们帮帮我,过了N组数据,连负数的考虑了,就是wa Posted by:lllsuper at 2009-07-15 10:01:02
#include<iostream>
#include<stdio.h>

using namespace std;

__int64 X,Y,M,N,L;

int main()
{
	scanf("%I64d%I64d%I64d%I64d%I64d",&X,&Y,&M,&N,&L);
	__int64 i;
	__int64 step,offset,speed;
	if(X==Y)
	{
		cout<<"0"<<endl;
		return 0;
	}
	if(M==N)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	if(X<Y&&M>N)
	{
		offset = Y-X;
		speed = M-N;
	}
	else if(X>Y&&M<N)
	{
		offset = X-Y;
		speed = N-M;
	}
	else if(X<Y&&M<N)
	{
		for(i=1;offset<=0;i++)
		{
			offset = X+L*i-Y;
		}
		speed = N-M;
	}
	else
	{
		for(i=1;offset<=0;i++)
		{
			offset = Y+L*i-X;
		}
		speed = M-N;
	}
	__int64 MaxLoop = 2100000000/L;
	for(i=0;i<MaxLoop;i++)
	{
		if((L*i+offset)%speed==0)
		{
			printf("%I64d\n",(L*i+offset)/speed);
			return 0;
		}
	}
	cout<<"Impossible"<<endl;
	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