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 dxtkdxtk at 2009-11-25 10:17:05 on Problem 1061
#include<stdio.h>
int tiao(int x,int m,int l)//从X跳M单位(总长l)
{
	x=x+m;
	if(x>l)
	x=x-l;
	return x;
}
int main()
{
	int x,y,m,n,l,t=0,i,j,k=0;
	while(scanf("%d%d%d%d%d",&x,&y,&m,&n,&l)!=EOF)
	{i=x;
	j=y;
	while(x!=y)
	{
		x=ti(x,m,l);
		y=ti(y,n,l);
		t++;
		if(x==i&&y==j)//如果跳回原位,则无限循环。
		{	
			printf("Impossible\n");
			k=1;
			break;
		}
	}
	if(k==0) printf("%d\n",t);
	}
	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