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 ssdfa7 at 2011-05-21 07:42:10 on Problem 1061
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	int x,y,m,n,len;
	while (cin>>x>>y>>m>>n>>len)
	{
		int dxy,dmn;
		x%=len;
		y%=len;
		dxy=y-x;
		dmn=n-m;
		if (x==y)
		{
			cout<<0<<endl;
			continue;
		}
		if (dxy<0) dxy=(len+dxy)%len;
		if (dmn<0)
		{
			dmn=-dmn;
			dxy=len-dxy;
		}
		if (dmn%len==0) cout<<"Impossible"<<endl;
		else 
		{
			if ((len-dxy)%dmn==0) cout<<(len-dxy)/dmn<<endl;
			else 
			{
				int cnt=0,sdxy=dxy;
				
				do
				{
					dxy+=dmn;
					dxy%=len;
					cnt++;
				}
				while (dxy!=0 && dxy!=sdxy);
				if (dxy==sdxy) cout<<"Impossible"<<endl;
				else cout<<cnt<<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