POJ 3349 Snowflake Snow Snowflakes

解题思路:hash

完整C++代码
   
     
#include < iostream >
using namespace std;
#define MAX_N 87719

struct node{
node():next(
0 ){}
int arm[ 6 ];
node
* next;
}snow[MAX_N];

int main()
{
int hash,n,i,j,k,t[ 6 ];
node
* cur, * pre;
bool isFind;
scanf(
" %d " , & n);
for (i = 0 ,isFind = false ;i < n;i ++ )
{
scanf(
" %d %d %d %d %d %d " ,t,t + 1 ,t + 2 ,t + 3 ,t + 4 ,t + 5 );
if (isFind) continue ;
hash
= (t[ 0 ] ^ t[ 1 ] ^ t[ 2 ] ^ t[ 3 ] ^ t[ 4 ] ^ t[ 5 ]) % MAX_N;
cur
= snow[hash].next;pre =& snow[hash];
while (cur &&! isFind)
{
for (j = 0 ;(j < 6 ) &&! isFind;j ++ )
{
for (k = 0 ;k < 6 ;k ++ )
if (t[(k + j) % 6 ] != cur -> arm[k]) break ;
if (k == 6 ){isFind = true ; break ;}
for (k = 0 ;k < 6 ;k ++ )
if (t[( 6 + j - k) % 6 ] != cur -> arm[k]) break ;
if (k == 6 )isFind = true ;
}
pre
= cur,cur = cur -> next;
}
if ( ! isFind){node * temp = new node();memcpy(temp -> arm,t, sizeof (t));pre -> next = temp;}
}
isFind
? printf( " Twin snowflakes found.\n " ):printf( " No two snowflakes are alike.\n " );
return 0 ;
}

 

你可能感兴趣的:(poj)