简单hash #includestdio.h#includestdlib.h;#includealgorithm#define inf 100001using namespace std; struct Edge{int a[10],next;}edge[100100];int a[10],head[100100],cnt;bool add(int * b){int sum=0,i,j,p,q;for(i=0;i6;i++)sum+=b[i];int hash=sum
简单hash
#include<stdio.h>
#include<stdlib.h>;
#include<algorithm>
#define inf 100001
using namespace std;
struct Edge{
int a[10],next;
}edge[100100];
int a[10],head[100100],cnt;
bool add(int * b){
int sum=0,i,j,p,q;
for(i=0;i<6;i++)
sum+=b[i];
int hash=sum%inf;
for(i=head[hash];i;i=edge[i].next){
for(j=0;j<6;j++){
if(edge[i].a[j]==b[0]){
for(p=0,q=j;p<6;p++){
if(b[p]!=edge[i].a[q])
break;
q=(q+1)%6;
}
if(p==6)return 1;
for(p=0,q=j;p<6;p++){
if(b[p]!=edge[i].a[q])
break;
q=(q-1+6)%6;
}
if(p==6)return 1;
}
}
}
++cnt;
for(i=0;i<6;i++)
edge[cnt].a[i]=b[i];
edge[cnt].next=head[hash];
head[hash]=cnt;
return 0;
}
int main(){
int i,j,n;
scanf("%d",&n);
bool flag=0;
for(i=1;i<=n;i++){
for(j=0;j<6;j++){
scanf("%d",&a[j]);
}
if(flag)continue;
if(add(a))flag=1;
}
if(flag)
printf("Twin snowflakes found.\n");
else
printf("No two snowflakes are alike.\n");
}