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

我想你的问题在于看下文

Posted by scpczc at 2007-06-09 22:12:31 on Problem 1182
In Reply To:我的食物链哪里有问题?高手GG帮帮忙看看 xx Posted by:herogxo at 2006-12-06 12:03:15
>
我想你的问题在于下面的代码付值错误.除了为a[x]=1;a[y]=2;以外,还可能为:a[x]=2;a[y]=3;或者a[x]=3,a[y]=1.解决办法我还没有想好.你自己再看看吧.如果说误了请指正.呵呵~
--------------------------传说中的分割线--------------------------
		if(a[x]==0&&a[y]==0)
		{
			if(d==1)
				a[x]=a[y]=1;//可能都为2或者3
			else                 //可能有上边的那种结果
			{
				a[x]=1;
				a[y]=2;
			}
		}

--------------------------传说中的分割线--------------------------



 //显示wrong answer 不知道哪里有问题 我自己输出的结果是对的 自己举了几个例子也符合 
> 
> #include <stdio.h>
> #define N 50000
> #define K 100000
> 
> int main()
> {
> 	int n,k,d,x,y,a[N+1],num=0,i;
> 	scanf("%d %d",&n,&k);
> 	for(i=0;i<=n;i++)
> 		a[i]=0;
> 	for(i=0;i<k;i++)
> 	{
> 		scanf("%d %d %d",&d,&x,&y);
> 		if(x>n||y>n)
> 		{
> 			num++;
> 			continue;
> 		}
> 		if(d==2&&x==y)
> 		{
> 			num++;
> 			continue;
> 		}
> 		if(a[x]==0&&a[y]==0)
> 		{
> 			if(d==1)
> 				a[x]=a[y]=1;
> 			else
> 			{
> 				a[x]=1;
> 				a[y]=2;
> 			}
> 		}
> 		else if(a[x]!=0&&a[y]!=0)
> 		{
> 			if(d==2&&(a[x]==1&&a[y]==3||a[x]==2&&a[y]==1||a[x]==3&&a[y]==2||a[x]==a[y]))
> 				num++;
> 			else if(d==1&&a[x]!=a[y])
> 				num++;
> 		}
> 		else if(a[x]==0)
> 		{
> 			if(d==1)
> 				a[x]=a[y];
> 			else
> 				a[x]=(a[y]+1)%3+1;
> 		}
> 		else if(a[y]==0)
> 		{
> 			if(d==1)
> 				a[y]=a[x];
> 			else
> 				a[y]=a[x]%3+1;
> 		}
> 	}
> 	printf("%d\n",num);
> 	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