大致题意:给出n片雪花,每片雪花有六个角,每个角由一个数字表示,如雪花A为(1,2,3,4,5,6),问是否有雪花是相同,相同的意思是比如还有雪花B(2,3,4,5,1,6),那么雪花A和B就是一样的
测试案例:
input:
21 2 3 4 5 64 3 2 1 6 5
output:
Twin snowflakes found.
解题思路:我是用纯粹的hash表写的,每次插入雪花时,判断这片雪花是否重复,这次的hash表也是用数组表示的,不过专门弄了个头结点数组和存放节点的数组,判断雪花是否重复我是把雪花的序号按从小到大存入hash表的,所以直接从最小的开比就行了
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node
{
int snow[6];
int pos;
};
int head[99991];
node hashtable[100000+10];
int cnt=0;
int main()
{
int n,i,j,a[6],k,t;
while (scanf("%d",&n)==1)
{
bool flag=true;
for (i=0;i<99991;i++)
head[i]=-1;
for (i=0; i<n; i++)
{
hashtable[i].pos=-1;
}
for (i=0; i<n; i++)
{
scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5]);
if (flag)
{
sort(a,a+6);
k=(a[0]+a[1]+a[2]+a[3]+a[4]+a[5])%99991;
for (t=head[k]; t!=-1; t=hashtable[t].pos)
{
if (hashtable[t].snow[0]==a[0])//我承认我这么写的唯一目的是看上去比较霸气
{
if (hashtable[t].snow[1]==a[1])
{
if (hashtable[t].snow[2]==a[2])
{
if (hashtable[t].snow[3]==a[3])
{
if (hashtable[t].snow[4]==a[4])
{
if (hashtable[t].snow[5]==a[5])
{
flag=false;
}
}
}
}
}
}
}
for (j=0; j<6; j++)
{
hashtable[cnt].snow[j]=a[j];
}
hashtable[cnt].pos=head[k];
head[k]=cnt;
cnt++;
}
}
if (flag)
printf("No two snowflakes are alike.\n");
else
printf("Twin snowflakes found.\n");
}
return 0;
}