After hashing, compare 6 times for each snowflake.
1#include <cstdio>2#include <cstring>3#include <vector>4#include <iostream>5#include <algorithm>6 7 using namespacestd;8 9 Const intMAXN =15010;Ten Const intPrime =14997; One A structFlake - { - intarm[6]; the BOOL operator== (Const structFlake b)Const - { - for(intI=0;i<6; i++) - { + intJ; - for(j=0;j<6; j + +) + { A if(arm[(j+i)%6]! = B.arm[j]) Break; at } - if(J = =6)return true; - } - for(intI=0;i<6; i++) - { - intJ; in for(j=0;j<6; j + +) - { to if(arm[(j+i)%6]! = b.arm[(6+(-1*J))%6]) Break; + } - if(J = =6)return true; the } * return false; $ }Panax Notoginseng }; - the structFlake hashtable[maxn][ -]; + A intHash (structFlake a) the { + intans=0; - for(intI=0;i<6; i++) $ { $Ans + = a.arm[i]%Prime; - } - returnans%Prime; the } - Wuyi intN; the intCONF[MAXN]; - Wu intMain () - { About while(~SCANF ("%d",&N)) $ { - Flake SN; - intFlag =0; -memset (Conf,0,sizeofconf); A for(intI=0; i<n;i++) + { the for(intI=0;i<6; i++) scanf ("%d",&sn.arm[i]); - if(flag)Continue; $ intKey =Hash (SN); the //printf ("key=%d\n", key); the the for(intI=0; i<conf[key];i++) the { - if(Hashtable[key][i] = = SN) flag =1; in } the if(!flag) hashtable[key][conf[key]++] =SN; the About } the if(flag) printf ("Twin Snowflakes found.\n"); the Elseprintf"No. Snowflakes is alike.\n"); the } +}
POJ 3349-snowflake Snow snowflakes-string Hash