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阿。。。help me...

Posted by liao14 at 2007-10-19 20:32:06 on Problem 3349
#include<iostream>
#include<algorithm>

using namespace std;

int num[1000];
struct node
{
	int a[6];
	node *next;
};

node *snow[1000];

bool match(node *a,node *b)
{
	int i,j,k;
	for( i = 0; i < 6; i ++ ) 
	{     
		if( a->a[0] == b->a[i] )     
		{      
			for( j = 0, k = i; j < 6; j ++ )      
			{       if( a->a[j] != b->a[k] )
			break;       
			k ++;       
			if ( k >= 6 )  k %= 6;      
			}      
			if( j == 6 ) return true;      
			for( j = 0, k = i; j < 6; j ++ )      
			{       
				if( a->a[j] != b->a[k] )        
					break;       
				k --;       
				if( k < 0 )        
					k = 5;      
			}      
			if( j == 6 ) return true;     
		}
	}
	return false;
}

int main()
{
	int i;
	bool flag;
	int n;
	while(scanf("%d",&n)>0)
	{
		memset(num,0,sizeof num);
		memset(snow,NULL,sizeof snow);
		flag=0;
		int nn[6];
		while(n--)
		{
			scanf("%d%d%d%d%d%d",&nn[0],&nn[1],&nn[2],&nn[3],&nn[4],&nn[5]);
			if(!flag)
			{
				int tmp=(nn[0]+nn[1]+nn[2]+nn[3]+nn[4]+nn[5])%100000;
				num[tmp]++;
				node *q=new node;
				for(i=0;i<6;i++) q->a[i]=nn[i];
				q->next =NULL;
				node *p=snow[tmp];
				if(p!=NULL)
				{
					while(1)
					{
						flag=match(p,q);
					    if(flag) break;
						if(p->next!=NULL) p=p->next;
						 else break;
					}
					p->next=q;
				}
				else snow[tmp]=q;
				
			}
		}
		if(flag) printf("Twin snowflakes found.\n");
			else printf("No two snowflakes are alike.\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