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 main() { unsigned long x,y,m,n,l,s,t=0; //t为跳的次数 scanf("%ld%ld%ld%ld%ld",&x,&y,&m,&n,&l); s = x - y; //s为两只青蛙的距离 if(s == 0) //一开始就在一起 printf("%ld\n",t); else { while(1) { x = x + m; y = y + n; x = x % l; //跳一次后的坐标 y = y % l; t++; if(x == y) //相遇 { printf("%ld\n",t); break; } else if(x-y == s || x-y == l-1) //两只青蛙的距离和开始一样 { printf("Impossible"); 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