雪花雪花雪花

写过不少, 没了。


#include<bits/stdc++.h>
using namespace std;

const int maxn = 100005;
int n, a[maxn][6];

namespace h
{
    
    int hed[maxn], nxt[maxn], ver[maxn], tot;
    
    int H(int ind)
    {
        int res = 0;
        for(int i=0; i<6; ++i) res = res xor a[ind][i];
        return (res % 100000) + 1;
    }
    
    void ins(int hashval, int b)
    {
        ver[++tot] = b;
        nxt[tot] = hed[hashval];
        hed[hashval] = tot;
    }
    
    bool eq(int inda, int indb)
    {
        bool res = false;
        // double zheng
        for(int i=0; i<6; ++i) for(int j=0; j<6; ++j) {
            bool nowres = true;
            for(int k=0; k<6; ++k) if(a[inda][(i+k)%6] != a[indb][(j+k)%6]) nowres = false;
            res |= nowres;
        }
        // one zheng one fan
        for(int i=0; i<6; ++i) for(int j=0; j<6; ++j) {
            bool nowres = true;
            for(int k=0; k<6; ++k) if(a[inda][(i+k)%6] != a[indb][(j-k+6)%6]) nowres = false;
            res |= nowres;
        }
        return res;
    }
    
    bool travel(int hashval, int ind)
    {
        for(int i=hed[hashval]; i; i=nxt[i]) if( eq(ver[i], ind) ) return true;
        return false;
    }
    
}

int main()
{
    
    scanf("%d", &n);
    for(int i=1; i<=n; ++i) {
        for(int j=0; j<6; ++j) scanf("%d", &a[i][j]);
        int Hash = h::H(i);
        if( h::travel(Hash, i) )
        {
            cout << "Twin snowflakes found." ;
            return 0;
        }
        h::ins(Hash, i);
    }
    cout << "No two snowflakes are alike." ;
    return 0;
    
}

原文地址:https://www.cnblogs.com/tztqwq/p/12243505.html