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 |
Re:能不能给一个原程序?In Reply To:能不能给一个原程序? Posted by:linmeng at 2005-07-06 10:30:09 Source Problem Id:1061 User Id:xfxyjwf Memory:28K Time:624MS Language:C++ Result:Accepted Source #include <stdio.h> void main() { unsigned long x,y,m,n,l; scanf("%ld %ld %ld %ld %ld",&x,&y,&m,&n,&l); if (m==n) printf("Impossible\n"); else { if(m>n) {m=m-n;x=(y-x+l)%l;} else {m=n-m;x=(x-y+l)%l;} //把其中移动比较慢的那个当做不动。 n=x/m;x=x%m;y=x; // 用相对运动的思想。 while(1) { if(y==0) {printf("%ld\n",n);break;} // 当两个人的距离等于零时 n=n+(y+l)/m;y=(y+l)%m; if(y==x) {printf("Impossible\n");break;} //当两个人的距离又回到 } //原来的距离表示不可能 } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator