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:有一小子非说他的程序没错,要起诉北大.我觉得他挺可怜的,但我也找不出错.哪位大哥来帮看看.(C语言)

Posted by cicero at 2007-11-23 22:08:51 on Problem 1061
In Reply To:有一小子非说他的程序没错,要起诉北大.我觉得他挺可怜的,但我也找不出错.哪位大哥来帮看看.(C语言) Posted by:20054959 at 2007-01-16 21:09:55
> #include<stdio.h>
> #include<math.h>
> void main()
> {
> unsigned long x,y,m,n,L,s,s1,t=0,v;
> scanf("%ld%ld%ld%ld%ld",&x,&y,&m,&n,&L);
> if(m==n)
> 	printf("Impossible\n");
> else 
> 	{
> 	if((x-y)*(m-n)<0)
> 		s=abs(x-y);
> 	else
> 		s=L-abs(x-y);
> 	x=s;
> 	v=abs(m-n);
> 	while(1)
> 		{
> 		s1=s%v;
> 		t=s/v+t;
> 		if(s1==0)
> 			{
> 			printf("%ld\n",t);
> 			break;
> 			}
> 		if((s1+L-x)%v==0)
> 			{
> 			printf("Impossible\n");
> 			break;
> 			}
> 		s=s1+L;
> 		}
> 	} 
> }

很简单啊,如果仅根据m == n 就判断永远不会相遇,这是不对的,当 x == y 时,步数为0就相遇了。。。就这一点,这个程序应该就不对。
而且,即使m != n, 也可能用不相遇

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