现在的位置: 首页 > 综合 > 正文

NYOJ 130 相同的雪花

2017年11月24日 ⁄ 综合 ⁄ 共 2006字 ⁄ 字号 评论关闭

相同的雪花

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述
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.

输入
The first line of the input will contain a single interger T(0<T<10),the number of the test cases.
The first line of every test case 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.
输出
For each test case,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.
样例输入
1
2
1 2 3 4 5 6
4 3 2 1 6 5
样例输出
Twin snowflakes found.

/*hash表*/

#include<cstdio>
#include<cstring>
const int N=19373;
int hash[N][100][6],b[N];
bool judge(int* a,int* b)
{
	int i,j;
	for(i=0; i<6; ++i)
	{
		for(j=0; j<6; ++j)
		{
			if(b[j]!=a[(i+j)%6])//顺时针查找 
				break;
		}
		if(j==6)
			return true;
		for(j=0; j<6; ++j)
		{
			if(b[j]!=a[(i+6-j)%6])//逆时针查找 
				break;
		}
		if(j==6)
			return true;
	}
	return false;
}
int main(){
	int T,n,sum,i,j,k,a[6];
	bool flag;
	scanf("%d",&T);
	while(T--)
	{
		flag = false;
		memset(b,0,sizeof(b));
		scanf("%d",&n);
		while(n--)
		{
			for(i=0,sum=0; i<6; ++i)
			{
				scanf("%d",&a[i]);
				sum+=a[i];
			}
			sum%=N;
			for(i=0; i<6; ++i)
				hash[sum][b[sum]][i] = a[i];
			b[sum]++;
		}
		for(k=0; k<N; ++k)
		{
			for(i=0; i<b[k]-1; ++i)
			{
				for(j=i+1; j<b[k]; ++j)
				{
					if(judge(hash[k][i],hash[k][j]))
					{
						flag = true;
						break;
					}
				}
				if(flag) break;
			}
			if(flag) break;
		}
		if(flag)
			printf("Twin snowflakes found.\n");
		else
			printf("No two snowflakes are alike.\n");
	}
	return 0;
} 

抱歉!评论已关闭.