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

AC了,不容易呀,搞笑,这样的测试数据也拿出来用,要不是看了大家的提示,现在还在郁闷呢。

Posted by 0huzi0 at 2008-08-05 09:28:09 on Problem 1182
#include<stdio.h>
struct ANM
{
	int value;
	int next;
};
int main()
{
//	freopen("1.txt","r",stdin);
	ANM anm[50000];
	int anmsum,wdsum,i,bh,e,be,hh=0,k=3,sum,qian,next;
    scanf("%d%d",&anmsum,&wdsum);
	{
		hh=0;
		k=3;
	for(i=0;i<anmsum;i++)
		anm[i].value=-1;
	while(wdsum--)
	{
		scanf("%d%d%d",&bh,&e,&be);
		if(e>anmsum || e<=0 || be>anmsum || be<=0)
			hh++;
		else
	    	if(bh==2 && e==be)
				hh++;
			else
			{
				e--;
				be--;
				if(anm[e].value==-1 && anm[be].value==-1)//都没连入
				{
					anm[e].value=k;
					if(bh==1)
					{
						anm[be].value=k;
					}
					else
					{
						anm[be].value=k+1;
					}
					anm[e].next=be;
					anm[be].next=e;
					k+=3;
				}
				else
					if(anm[e].value!=-1 && anm[be].value==-1)
					{
						sum=anm[e].value/3*3;
					    if(bh==1)
						{
							anm[be].value=anm[e].value;
						}
						else
						{
							anm[be].value=(anm[e].value+1)%3+sum;
						}
						anm[be].next=anm[e].next;
						anm[e].next=be;
					}
					else
						if(anm[e].value==-1 && anm[be].value!=-1)
						{
							sum=anm[be].value/3*3;
							if(bh==1)
							{
								anm[e].value=anm[be].value;
							}
							else
							{
								anm[e].value=(anm[be].value+2)%3+sum;
							}
							anm[e].next=anm[be].next;
							anm[be].next=e;							
						}
						else
						{
							if(anm[e].value/3==anm[be].value/3)
							{
								if(!(((anm[e].value-anm[be].value+3)%3==2 && bh==2) ||
									(anm[e].value==anm[be].value && bh==1)))
									hh++;
								continue;
							}
							sum=anm[e].value/3*3;
							qian=anm[be].value;
							if(bh==1)
							{
					    		anm[be].value=anm[e].value;
							}
					    	else
							{
								anm[be].value=(anm[e].value+1)%3+sum;
							}
							next=anm[be].next;
							while(anm[next].next!=be)
							{
								anm[next].value=(anm[next].value-qian+anm[be].value+3)%3+sum;
								next=anm[next].next;
							}
							anm[next].value=(anm[next].value-qian+anm[be].value+3)%3+sum;
							anm[next].next=anm[e].next;
							anm[e].next=be;
						}
			}
	}
	printf("%d\n",hh);
	}
	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