Give the 6 sides of the N hexagon, asking if there are exactly the same two hexagons, exactly the same length and position as the edges. The order of the edges is counterclockwise or clockwise.
Give each 6-edge a hash value by the square and modulo of the 6-edge length
#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intMAXN =1e6;Const intMoD =999983; a typedef of large primes within//100wLong LongLL;intN;Chars[100010][Ten];intHASH[MAXN],NEXT[MAXN];BOOLJudgeintAintb) { inti,j,k; for(i =0; I <6; ++i)//The starting position of the string { for(j = I,k =0; K <6; ++k,j = (j+1)%6)//Clockwiseif(S[a][k]! = S[b][j]) Break; if(k = =6)return true; for(j = I,k =0; K <6; ++k, j = (j+5)%6)//counter-clockwiseif(S[a][k]! = S[b][j]) Break; if(k = =6)return true; } return false;}intMain () {//freopen ("in", "R", stdin);scanf"%d",&N); BOOLFlag =false; for(inti =1; I <= N; ++i) {intx =0, U; for(intj =0; J <6; ++j) {scanf ("%d",&S[i][j]); X= (int) ((x+ (LL) s[i][j]* (LL) s[i][j])%mod);//Prevent overflow} u=Hash[x];//hash "" contains the line number of a line corresponding to the hash value. while(u) {if(Judge (I,u)) {flag =true; Break;} Just u!. =0, indicating that the hash value has occurred before, you may appear the same hexagon, judging the U=next[u];//go down the "linked list"if(flag) Break; Next[i]=hash[x];//similar to the insertion method of the linked list, the hash value of the same together, convenient for later use next can be traversed to all the same side of the hash hash[x]=i;//Update table header}if(flag) printf ("Twin Snowflakes found.\n"); Elseprintf"No. Snowflakes is alike.\n");}
poj3349 (hash + chain address method)