描述:不只哈希可以过,直接暴也可以
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define N 10003
typedef long State[55][55];
State s[N],num;
int n,Sum,flag;
int head[N],next[N];
bool cmp(long (*p)[55],long (*q)[55])
{
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if(p[i][j]!=q[i][j]) return true;
return false;
}
void calculate(int count)
{
next[Sum]=head[count];
head[count]=Sum;
Sum++;
}
void rotate_90(int c)
{
int x=1,y=1,count=0;
for(int i=1; i<=n; i++)
for(int j=n; j>0; j--)
{
s[Sum][x][y++]=s[c][j][i];
if(y==n+1)
{
y=1;
x++;
}
count=(count*2+s[c][j][i])%N;
}
calculate(count);
}
void rotate_180(int c)
{
int x=1,y=1,count=0;
for(int i=n; i>0; i--)
for(int j=n; j>0; j--)
{
s[Sum][x][y++]=s[c][i][j];
if(y==n+1)
{
y=1;
x++;
}
count=(count*2+s[c][i][j])%N;
}
calculate(count);
}
void rotate_270(int c)
{
int x=1,y=1,count=0;
for(int i=n; i>0; i--)
for(int j=1; j<=n; j++)
{
s[Sum][x][y++]=s[c][j][i];
if(y==n+1)
{
y=1;
x++;
}
count=(2*count+s[c][j][i])%N;
}
calculate(count);
}
void solve()
{
int count=0;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
s[Sum][i][j]=num[i][j];
count=(count*2+num[i][j])%N;
}
int c=head[count];
while(c!=-1)
{
if(!cmp(s[Sum],s[c]))
{
flag=1;
return;
}
c=next[c];
}
next[Sum]=head[count];
head[count]=Sum;
c=Sum++;
rotate_90(c);
rotate_180(c);
rotate_270(c);
}
int main()
{
// freopen("a.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
if(!n) break;
memset(head,-1,sizeof(head));
memset(next,-1,sizeof(next));
memset(num,0,sizeof(num));
int x,y,count;
char c;
flag=Sum=0;
for(int i=1; i<=2*n; i++)
{
scanf("%d %d %c",&x,&y,&c);
if(c=='+') num[x][y]=1;
else num[x][y]=0;
if(!flag) solve();
if(flag==1)
{
count=i;
flag=2;
}
}
if(!flag) puts("Draw");
else
{
if(count%2==1) printf("Player 2 wins on move %d\n",count);
else printf("Player 1 wins on move %d\n",count);
}
}
return 0;
}