# A - SnowflakeSnowSnowflakes解题报告（黄杰）

A - SnowflakeSnowSnowflakes
Time Limit:4000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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.

#include<stdio.h>
#include<memory.h>
const int M=50021;//定义一个大素数，从而通过取模减小内存。
int hash[50022][7],sel[50022],a[100001][7];
int main()
{
int n,i,j,sum,k,ok1,ok2,ok3;
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<6;j++)
scanf("%d",&a[i][j]);
memset(sel,0,sizeof(sel));
memset(hash,0,sizeof(hash));
ok3=0;
for(i=0;i<n;i++)
{
sum=0;
for(j=0;j<6;j++)
sum+=a[i][j];
sum=sum%M;//因为sum可能很大，所以对一个大素数取模，这样减小hash数列的范围。
if(sel[sum]==0)//sel数组用来判断此时hash数组上对应的是否已存在，不存在则记录1，且将此部分赋给hash数组。
{
sel[sum]=1;
for(k=0;k<6;k++)
hash[sum][k]=a[i][k];
}
else//如该位置上已存在，则比较是否相同。
{
for(k=0;k<6;k++)//比较两集合是否互为子集。
{
ok1=0;
for(j=0;j<6;j++)
if(hash[sum][k]==a[i][j])
{
ok1=1;
break;
}
if(ok1==0)
{
break;
}
}
for(k=0;k<6;k++)
{
ok2=0;
for(j=0;j<6;j++)
if(hash[sum][j]==a[i][k])
{
ok2=1;
break;
}
if(ok2==0)
break;
}
if(ok1==1&&ok2==1)//互为子集则有相同的，输出并退出，不用再循环。
{
printf("Twin snowflakes found.\n");
ok3=1;
break;
}
}
}
if(ok3==0)
printf("No two snowflakes are alike.\n");
return 0;
}

#### POJ3349-Snowflake Snow Snowflakes

2011-07-30 21:39:40

#### A - SnowflakeSnowSnowflakes解题报告

2012-03-23 08:51:47

#### F - Babelfish解题报告（黄杰）

2012-03-21 13:43:39

#### D - Eqs解题报告（黄杰）

2012-03-21 13:41:43

#### J - Pie解题报告（黄杰）

2012-03-21 13:36:47

#### 福利：饿了么《分布式时序数据库 - LinDB》！

2018-04-23 17:44:59

#### G - Monthly Expense解题报告（黄杰）

2012-03-21 13:38:55

#### I - Expanding Rods解题报告（黄杰）

2012-03-21 13:46:20

#### 【LeetCode】Reverse Nodes in k-Group 解题报告

2014-12-17 17:01:26

#### 杭电OJ题 1393 Weird Clock解题报告

2013-01-18 19:46:00