uva 141 The Spot Game

#include<stdio.h>
#include<string.h>
#include<set>
#define max 55
int n;
using namespace std;
struct state{
int State[max][max];
friend bool operator<(const state &a,const state &b)
{
int i,j;
for(i=1;i<=n;i++)
for( j=1;j<=n;j++)
if(a.State[i][j] < b.State[i][j])
return true;
if(a.State[i][j] > b.State[i][j])
return false;
return false;
}
}sta;
set<state>s;
void rotate(state *p )
{
int i,j;
int a[max][max];
memset(a,0,sizeof(a));
memcpy(a,p->State,sizeof(p->State));
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
p->State[j][n-i+1]=a[i][j];
}
}
}
int main()
{
int i,j,k,flag;
for(;;)
{
scanf("%d",&n);
if(n==0)
break;
s.clear();
memset(sta.State,0,sizeof(sta.State));
flag=0;
int step[150][2];
char ch1[150];
for(i=1;i<=n*2;i++)
{
scanf("%d %d %c",&step[i][0],&step[i][1],&ch1[i]);
}
for(i=1;i<=n*2;i++)
{
int x,y;
x=step[i][0];
y=step[i][1];
char ch=ch1[i];
if(ch=='+')
sta.State[x][y]=1;
if(ch=='-')
sta.State[x][y]=0;
if(s.find(sta)!=s.end())
{
flag=1;
break;
}
else
{
state tmp,tmp1,tmp2,tmp3;
memcpy(&tmp,&sta,sizeof(sta));
s.insert(tmp);
memcpy(&tmp1,&tmp,sizeof(tmp));
rotate(&tmp1);
s.insert(tmp1);
memcpy(&tmp2,&tmp1,sizeof(tmp1));
rotate(&tmp2);
s.insert(tmp2);
memcpy(&tmp3,&tmp2,sizeof(tmp2));
rotate(&tmp3);
s.insert(tmp3);
}
}
if(flag==1)
{
if(i%2!=0)
printf("Player 2 wins on move %d\n",i);
else 
printf("Player 1 wins on move %d\n",i);
}
if(i>n*2)
printf("Draw\n");
}
return 0;
}


































你可能感兴趣的:(c)