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

哪位大神帮我看看啊,为什么WA啊,在下感激万分~

Posted by littlezhao at 2010-03-20 13:01:09 on Problem 1139
#include<stdio.h>	
int catway[101][101];
int mouseway[101][101];
int pre[101];
int main(void)
{
	int n,cat,mouse,i,j,x,y,flag;
	int cas;
	int changed;
	scanf("%d",&cas);
	while(cas--)
	{
		flag=0;
		changed=1;
		scanf("%d%d%d",&n,&cat,&mouse);
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				catway[i][j]=mouseway[i][j]=0;
		catway[cat][cat]=1;
		mouseway[mouse][mouse]=1;
		while(scanf("%d%d",&x,&y)&&(x!=-1||y!=-1))
		{
			catway[x][y]=1;
		}
		while(changed)
		{
			changed=0;
			for(i=1;i<=n;i++)
			{
				for(j=1;j<=n;j++)
					if(catway[cat][i]&&catway[i][j]&&!catway[cat][j])
					{
						catway[cat][j]=1;
						changed=1;
					}
			}
		}
		changed=1;
		while(scanf("%d%d",&x,&y)&&(x!=-1||y!=-1))
		{
			mouseway[x][y]=1;
			pre[y]=x;
		}
		while(changed)
		{
			changed=0;
			for(i=1;i<=n;i++)
			{
				for(j=1;j<=n;j++)
					if(mouseway[mouse][i]&&mouseway[i][j]&&!mouseway[mouse][j])
					{
						changed=1;
						mouseway[mouse][j]=1;
						pre[j]=i;
					}
			}
		}
		for(i=1;i<=n;i++)
		{
			if(mouseway[mouse][i]&&catway[cat][i])
			{
				printf("Y ");
				break;
			}
		}
		if(i==n+1)
			printf("N ");
		for(i=1;i<mouse;i++)
			if(mouseway[mouse][i]&&mouseway[i][mouse])
			{
				for(j=i;j!=mouse;j=pre[j])
					if(catway[cat][j])
						break;
				if(j==mouse)
				{
					flag=1;
					break;
				}
			}
		if(flag==0)
		{
			for(i=mouse+1;i<=n;i++)
				if(mouseway[mouse][i]&&mouseway[i][mouse])
				{
					for(j=i;j!=mouse;j=pre[j])
						if(catway[cat][j])
							break;
					if(j==mouse)
					{
						flag=1;
						break;
					}
				}
		}
		if(flag)
			printf("Y\n");
		else
			printf("N\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