Snowflake Snow Snowflakes

题意: 给定一个n个六边形雪花,判定是否存在相同的
分析: 链表hash
hash 值是所有的乘积以及和



const int P = 99991;
const int maxn = 100000+100;
int snow[maxn][6],tot;
int head[maxn],nxt[maxn];
int cal(int *a){
    int sum,mul;
    sum = mul = 0;
    for(int i = 0;i < 6; ++i){
        sum = (sum+a[i])%P;
        mul = 1ll*mul*a[i]%P;
    }
    return (sum+mul)%P;
}
bool cmp(int *a,int *b){

    for(int j = 0;j < 6; ++j){
        bool yes = true;
        for(int k = 0;k < 6; ++k)
            if(a[k] != b[(j+k)%6]) yes = false;
        if(yes) return true;
        yes = true;
        for(int k = 0;k < 6; ++k)
            if(a[k] != b[(j-k+6)%6]) yes = false;
        if(yes) return true;
    }
    return false;
}
bool Insert(int *a){
    int n = cal(a);
    // cout<<n<<endl;
    for(int i = head[n];i;i = nxt[i]){
        if(cmp(snow[i],a))
            return true;
    }
    ++tot;
    memcpy(snow[tot],a,sizeof(snow[tot]));
    nxt[tot] = head[n];
    head[n] = tot;
    return false;
}
int main(void)
{
    int n;int a[6];
    cin>>n;
    for(int i = 1;i <= n; ++i){
        for(int j = 0;j < 6; ++j)scanf("%d",&a[j]);
        if(Insert(a)){
            return 0*puts("Twin snowflakes found.");
        }
    }
    puts("No two snowflakes are alike.");
    

   return 0;
}