| ||||||||||
| 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。。= =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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator