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

超时,大虾帮忙看看

Posted by sunjingna at 2005-07-27 03:36:28 on Problem 1061
#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:
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