| ||||||||||
| 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 | |||||||||
二十几次了,还是错误,哪位大侠帮忙看看(G++)#include <stdio.h>
long long x;
long long y;
long long m;
long long n;
long long L;
long long times;
bool caculate( long long pos, long long rate, long long L);
bool doit( long long x, long long y, long long m, long long n, long long L)
{
long long rate;
long long pos;
if(x==y ||x <0||y <0||
x>= 2000000000||
y>= 2000000000||
m>= 2000000000||
n>= 2000000000||
L>= 2100000000||
m <=0 || n <=0 || m==n || L <=0)
{
return false;
}
x%=L;
y%=L;
if(x==y)
{
return false;
}
m%=L;
n%=L;
if(m==n)
{
return false;
}
if(m>n) // A的速度快
{
rate=m-n;
if(y>x)
{
pos=y-x;
}
else
{
pos=y+L-x;
}
}
else
{
rate=n-m;
if(x>y)
{
pos=x-y;
}
else
{
pos=x+L-y;
}
}
if(rate>L/2) //从末端来追,可以减少循环的次数
{
return caculate(L-pos,L-rate,L);
}
else
{
return caculate(pos,rate,L);
}
}
bool caculate( long long pos, long long rate, long long L)
{
if(L%2==0 && pos%2==1 && rate%2==0)
{
return false;
}
if(pos%rate!=0 && L%rate==0)
{
return false;
}
long long c=pos%rate;
long long d = pos;
long long e=d%rate;
while(e!= 0)
{
d += L;
e=d%rate;
if(e==c)
{
return false;
}
}
times = d/rate;
return true;
}
int main(void)
{
scanf("%d %d %d %d %d",&x, &y, &m, &n, &L);
if( doit( x, y, m, n, L))
{
printf("%ld\n",times);
}
else
{
printf("Impossible\n");
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator