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

1000组数据全部通过但是wa!!!!看代码

Posted by HH_YT at 2012-03-28 20:25:16 on Problem 1061
#include<stdio.h>
long x,y,m,n,l;//x y:坐标 m,n:跳跃距离 l:地球周长
long cut(long a,long b) //跳跃距离之差
{
	if(a>b)
		return a-b;
	else
		return b-a;
}
long check(long num,long l,long distance)//检查能否跳到同一个点(相对位移能否变为0,不能就返回0,能就返回跳多少步)
{
	long flag=0;
	long n;
	for(long i=0;i<=num;i++)//如果相对位移出现了一样就一定跳不到同一个点(每个可能的相对位移都出现就一定能出现相同的相对位移)
	{
		if((l*i+distance)%num==0)
		{
			flag=1;
			n=i;
			break;
		}
	}
	if(flag==0)
		return 0;
	else
	{
		return (l*n+distance)/num;
	}
}
int main()
{
	long distance;
//	if(freopen("D:读入数据.txt", "r", stdin)==NULL)
//		printf("000!");
//	if(freopen("D:输出数据.txt","w",stdout)==NULL)
//		printf("111!");
//	while(1)
//	{
	if(scanf("%ld%ld%ld%ld%ld",&x,&y,&m,&n,&l)==EOF)
		return 1;
	if(m>n)
	{
		if(x>y)
			distance=l-(x-y);
		else if(x==y)
			distance=0;
		else
			distance=y-x;
	}
	else
	{
		if(x>y)
			distance=x-y;
		else if(x==y)
			distance=0;
		else
			distance=l-(y-x);
	}
	long num=cut(m,n);
	if(num!=0)
	{
	long flag=check(num,l,distance);
	if(flag==0)
	{
		printf("Impossible\n");
	}
	else
		printf("%ld\n",flag);
	}
	if(num==0)
	{
		if(distance!=0)
			printf("Impossible\n");
		else
			printf("1\n");
	}
//	}
	return 0;
}

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