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

3200ms~~~ 求指点!

Posted by 569262726 at 2012-03-10 20:44:33 on Problem 3349
#include<iostream>
#include<vector>
using namespace std;
const int N=9997;
int i,j,k,snownum;
struct set
{
	int num[6],sum;
};
vector<set> hash[N];
bool contrast(set a,set b)
{
	for(int i=0;i<6;i++)
	{
		if(a.num[0]==b.num[i%6] && a.num[1]==b.num[(i+1)%6] && a.num[2]==b.num[(i+2)%6] && a.num[3]==b.num[(i+3)%6] && a.num[4]==b.num[(i+4)%6] && a.num[5]==b.num[(i+5)%6])
			return true;
		if(a.num[5]==b.num[i%6] && a.num[4]==b.num[(i+1)%6] && a.num[3]==b.num[(i+2)%6] && a.num[2]==b.num[(i+3)%6] && a.num[1]==b.num[(i+4)%6] && a.num[0]==b.num[(i+5)%6])
			return true;
	}
	return false;
}
bool search()
{
	for(i=0;i<N;i++)
	{
		for(j=0;j<hash[i].size();j++)
			for(k=j+1;k<hash[i].size();k++)
			{
				if(hash[i][j].sum==hash[i][k].sum  && contrast(hash[i][j],hash[i][k]))
					return true;
			}
	}
	return false;
}
int main()
{
	set temp;
	scanf("%d",&snownum);
	for(i=1;i<=snownum;i++)
	{
		temp.sum=0;
		for(j=0;j<6;j++)
		{
			scanf("%d",&temp.num[j]);
			temp.sum+=temp.num[j];
		}
		hash[temp.sum%N].push_back(temp);
	}
	puts(search()?"Twin snowflakes found.":"No two snowflakes are alike.");
	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