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

Re:能不能给一个原程序?

Posted by xfxyjwf at 2005-07-06 11:29:45 on Problem 1061
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:
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