| ||||||||||
| 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 | |||||||||
超时,大虾帮忙看看#include<iostream>
using namespace std;
int main()
{
int temp,st,v,x,y,m,n,l,step=0;
cin>>x>>y>>m>>n>>l;
if(m==n&&x!=y)
{
cout<<"Impossible"<<endl;
}
else
{
if(m>n)
{
temp=m;m=n;n=temp;
temp=x;x=y;y=temp;
}
v=n-m;
if(x==y)
{
cout<<step<<endl;
}
else
{
if(y>x)
st=y-x;
else
st=l-x+y;
y=st;
while(1)
{
if((l-st)%v==0)
{
step+=(l-st)/v;
cout<<step<<endl;
break;
}
else
{
st+=(l-st)/v*v+v-l;
step+=(l-st)/v+1;
}
if(st==y)
{
cout<<"Impossible"<<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