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<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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator