/*
哈希第一题啊..! 谢谢 http://www.cnblogs.com/Dario67/archive/2011/04/09/2010724.html 的博主
这题投机取巧了,判断是否相等 直接排序 比较相等 混过去了 实际题目意思不是这样的 呵呵
*/
#include <stdio.h>
#include <stdlib.h>
#define M 99991 //大素数 这是怎么来的我还不清楚
#define MAXN 100000
struct flake{
int arm[6];
struct flake *next; //拉链法处理冲突
void init(){
next = NULL;
}
}snow[MAXN];
int hash(int a[]){
return ((a[0] + a[2] + a[4]) & (a[1] + a[3] + a[5])) % M; //discuss里复制的...
}
bool same(int a[], int b[]){
for(int i = 0; i < 6; ++i){
if(a[i] != b[i])
return false;
}
return true;
}
bool search(int idx, int arm[]){
flake *p = &snow[idx];
p = p -> next;
while( p ){
if( same(p -> arm, arm)){
return true;
}
p = p -> next;
}
return false;
}
void insert(int idx, flake *newsnow){
flake *p = &snow[idx];
newsnow -> next = p -> next;
p -> next = newsnow;
}
int cmp(const void *a, const void *b){
return *(int*)a - *(int*)b;
}
int main(){
int n;
bool find = false;
flake *nsnow;
for(int i = 0; i < MAXN; ++i)
snow[i].init();
scanf("%d",&n);
for(int i = 0; i < n; ++i){
nsnow = (flake*)malloc(sizeof(flake));
for(int j = 0; j < 6; ++j){
scanf("%d",&nsnow -> arm[j]);
}
qsort(nsnow -> arm, 6, sizeof(int), cmp);
int idx = hash(nsnow -> arm); //找到散列值
//printf("%d\n",idx);
if(!search(idx, nsnow -> arm)){ //没插入过
insert(idx, nsnow);
} else {
printf("Twin snowflakes found.\n");
return 0;
}
}
printf("No two snowflakes are alike.\n");
return 0;
}