链接:Snowflake Snow Snowflakes

判断所有的雪花里面有没有相同的

每次把雪花每个角的值进行相加和相乘 之后hash 

#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
using namespace std;
typedef long long LL;
const int maxn = 1000005;
int tot = 0,p=99991;
int snow[maxn][6],head[maxn],nex[maxn];
int he(int *a){
  int sum=0,mul=1;
  for(int j=0;j<6;j++){
     sum=(sum+a[j])%p;
     mul=1LL*mul*a[j]%p;
  }
  return (sum+mul)%p;
}
bool equa(int *a,int *b){
   sort(a,a+6);
   sort(b,b+6);
   for(int j=0;j<6;j++){
     if(a[j]!=b[j]) return 0;
   }
   return 1;
}
bool inse(int *a){
   int val=he(a);
   //cout<<val<<endl;
   for(int j=head[val];j;j=nex[j]){
      if(equa(snow[j],a)){
        return 1;
      }
   }
   ++tot;
   memcpy(snow[tot],a,6*sizeof(int));
   nex[tot]=head[val];
   head[val]=tot;
   return 0;
}
int main(){
   int n;
   cin>>n;
   memset(head,-1,sizeof(head));
   memset(nex,-1,sizeof(nex));
   for(int j=1;j<=n;j++){
      int a[10];
      for(int j=0;j<6;j++){
        scanf("%d",&a[j]);
      }
      if(inse(a)){
         puts("Twin snowflakes found.");
         return 0;
      }
   }
   puts("No two snowflakes are alike.");
}