http://acm.pku.edu.cn/JudgeOnline/problem?id=3349
这道题用的hash表,开始用开放寻址法,alwayTLE,于是建了一个二维数组模拟拉链,过了,经过反复测试,用的是15000*10的。取mod的数的14997.
#include < iostream >
using   namespace  std;
#define  prime 14997
int  a[ 100001 ][ 6 ];
int  hash[ 15000 ][ 10 ];
int  cop[ 12 ];
int  n,len;
int  i,j,k,inde;
bool  flag = 0 ;
int  add;
int  p;
int  clockwise( int  k) // 顺时针
{    int  t;
    
if (k + 5 >= 12 )
       
return   0 ;
    
for (t = k;t < k + 6 ;t ++ )
    {   
        
if (cop[t] != a[hash[add][p]][t - k])
            
return   0 ;
    }
    
return   1 ;
}
int  counterclockwise( int  k) // 逆时针
{     int  t;
     
if (k - 5 < 0 )
        
return   0 ;
     
for (t = k;t > k - 6 ;t -- )
     {   
         
if (cop[t] != a[hash[add][p]][k - t])
             
return   0 ;
     }
     
return   1 ;
}
int  same()
{    
     
for (k = 0 ;k < 6 ;k ++ )
     {   
         cop[k]
= a[i][k];
         cop[k
+ 6 ] = a[i][k];
     }
     
for (k = 0 ;k < 12 ;k ++ )
     {    
          
if (cop[k] == a[hash[add][p]][ 0 ])
          {    
if (clockwise(k) || counterclockwise(k))
                    
return   1 ;
          }
     }
     
return   0 ;
}
int  solve( int  inde)
{    p
= 0 ;
     add
= inde % prime;
     
if ( ! hash[add][p])
     {   hash[add][p]
= i;
         
return   0 ;
     }
     
else  
     {   
while (hash[add][p])
         {   
             
if (same())
             {  
                   flag
= 1 ;
                   
return   0 ;
             }
             p
++ ;
         }
         hash[add][p]
= i;
     }
     
return   0 ;
}

int  main()
{   memset(hash,
0 , sizeof (hash));
    scanf(
" %d " , & n);
    
for (i = 1 ;i <= n;i ++ )
    {    inde
= 0 ;
         
for (j = 0 ;j < 6 ;j ++ )
         {    
              scanf(
" %d " , & a[i][j]);
              inde
+= a[i][j];
         }
         solve(inde);
         
if (flag)
         {   printf(
" Twin snowflakes found.\n " );
             system(
" pause " );
             
return   0 ;
         }
         
    }
    
if ( ! flag)
       printf(
" No two snowflakes are alike.\n " );
    system(
" pause " );
    
return   0 ;
}