poj--3349--Snowflake Snow Snowflakes(폭력)

Snowflake Snow Snowflakes
Time Limit: 4000MS
 
Memory Limit: 65536K
Total Submissions: 18980
 
Accepted: 4926
Description
You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and search for a pair that may be identical. Each snowflake has six arms. For each snowflake, your program will be provided with a measurement of the length of each of the six arms. Any pair of snowflakes which have the same lengths of corresponding arms should be flagged by your program as possibly identical.
Input
The first line of input will contain a single integer n, 0 < n ≤ 100000, the number of snowflakes to follow. This will be followed by n lines, each describing a snowflake. Each snowflake will be described by a line containing six integers (each integer is at least 0 and less than 10000000), the lengths of the arms of the snow ake. The lengths of the arms will be given in order around the snowflake (either clockwise or counterclockwise), but they may begin with any of the six arms. For example, the same snowflake could be described as 1 2 3 4 5 6 or 4 3 2 1 6 5.
Output
If all of the snowflakes are distinct, your program should print the message: No two snowflakes are alike. If there is a pair of possibly identical snow akes, your program should print the message: Twin snowflakes found.
Sample Input
2
1 2 3 4 5 6
4 3 2 1 6 5

Sample Output
Twin snowflakes found.

제목: N개의 눈송이를 준다는 뜻입니다. 눈송이마다 6개의 테두리가 있습니다. 똑같은 눈송이가 2개 있는지 물어보세요.
이 문제는 테스트 데이터에 문제가 있기 때문에 많은 사람들이 직접 정렬하면 지나간다
이 문제는 또 동구의 문제인지 아닌지를 고려해야 한다

1 2 3 4 5 6
3 1 2 4 6 5
 :No two snowflakes are alike.

따라서 순서를 정한 후에 눈송이 원래의 모습이 같은 구조에 부합되는지 비교해야 한다.
#include<iostream>
#include <ctime>
#include <algorithm>
using namespace std;

int num[100010][12];
bool judge;
int cmp(const void *c,const void *d)
{
	int *p=(int*)c;
	int *q=(int*)d;
	sort(p,p+6);
	sort(q,q+6);
	int i;
	for( i=0;i<6;i++)
		if(p[i]!=q[i])
			return p[i]-q[i];
	if(i==6)
	{
		return 0;
	}
}
bool cmp2(int *p,int *q)
{
	if(p[0]==q[0]&&p[1]==q[1]&&p[2]==q[2]&&p[3]==q[3]&&p[4]==q[4]&&p[5]==q[5])
		return true;
	if(p[0]==q[1]&&p[1]==q[2]&&p[2]==q[3]&&p[3]==q[4]&&p[4]==q[5]&&p[5]==q[0])
		return true;
	if(p[0]==q[2]&&p[1]==q[3]&&p[2]==q[4]&&p[3]==q[5]&&p[4]==q[0]&&p[5]==q[1])
		return true;
	if(p[0]==q[3]&&p[1]==q[4]&&p[2]==q[5]&&p[3]==q[0]&&p[4]==q[1]&&p[5]==q[2])
		return true;
	if(p[0]==q[4]&&p[1]==q[5]&&p[2]==q[0]&&p[3]==q[1]&&p[4]==q[2]&&p[5]==q[3])
		return true;
	if(p[0]==q[5]&&p[1]==q[0]&&p[2]==q[1]&&p[3]==q[2]&&p[4]==q[3]&&p[5]==q[4])
		return true;
	if(p[0]==q[0]&&p[5]==q[1]&&p[4]==q[2]&&p[3]==q[3]&&p[2]==q[4]&&p[1]==q[5])
		return true;
	if(p[0]==q[1]&&p[5]==q[2]&&p[4]==q[3]&&p[3]==q[4]&&p[2]==q[5]&&p[1]==q[0])
		return true;
	if(p[0]==q[2]&&p[5]==q[3]&&p[4]==q[4]&&p[3]==q[5]&&p[2]==q[0]&&p[1]==q[1])
		return true;
	if(p[0]==q[3]&&p[5]==q[4]&&p[4]==q[5]&&p[3]==q[0]&&p[2]==q[1]&&p[1]==q[2])
		return true;
	if(p[0]==q[4]&&p[5]==q[5]&&p[4]==q[0]&&p[3]==q[1]&&p[2]==q[2]&&p[1]==q[3])
		return true;
	if(p[0]==q[5]&&p[5]==q[0]&&p[4]==q[1]&&p[3]==q[2]&&p[2]==q[3]&&p[1]==q[4])
		return true;
	return false;
}
int main()
{
	int k=0,i,j,t,n;
//	freopen("a.out","r",stdin);
	double q=clock();
	while(scanf("%d",&n)!=EOF)
	{
		judge=false;
		for(j=0;j<n;j++)
			for(i=0;i<6;i++)
			{
				scanf("%d",&num[j][i]);
				num[j][i+6]=num[j][i];
			}
		qsort(num,n,sizeof(num[0]),cmp);
		for(j=1;j<n;j++)
		{
			if(cmp2(num[j]+6,num[j-1]+6))
				judge=true;
		}
		if(judge)
			printf("Twin snowflakes found.
"); else printf("No two snowflakes are alike.
"); } //printf("%lf
",clock()-q); }

좋은 웹페이지 즐겨찾기