UVa:141 The Spot Game

判断每次操作后的状态是否曾经出现或者旋转后是否曾经出现。

数据很小,保存每次操作后的状态判断一下就行了。

我一开始没审好题以为全都是4*4的格子,居然WA了而不是RE。。囧。。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct State
{
    bool flag[55][55];
    State()
    {
        memset(flag,0,sizeof(flag));
    }
};
int N;
bool Judge(State x,State y)
{
    for(int i=1; i<=N; ++i)
        for(int j=1; j<=N; ++j)
            if( x.flag[i][j]!=y.flag[i][j])
                return false;
    return true;
}
void Rotat_90(State &x)
{
    State tmp=x;
    for(int i=1; i<=N; ++i)
        for(int j=1; j<=N; ++j)
            x.flag[i][j]=tmp.flag[N+1-j][i];
}
int main()
{
    while(scanf("%d",&N)&&N)
    {
        int x,y;
        char p[3];
        int ans=0;
        State now[200];
        for(int i=1; i<=2*N; ++i)
        {
            scanf("%d%d%s",&x,&y,&p);
            now[i]=now[i-1];
            if(p[0]=='+')
                now[i].flag[x][y]=true;
            else
                now[i].flag[x][y]=false;
            for(int j=1; j<i&&!ans; ++j)
            {
                State tmp=now[i];
                if(Judge(tmp,now[j]))
                    ans=i;
                else
                {
                    Rotat_90(tmp);
                    if(Judge(tmp,now[j]))
                        ans=i;
                    else
                    {
                        Rotat_90(tmp);
                        if(Judge(tmp,now[j]))
                            ans=i;
                        else
                        {
                            Rotat_90(tmp);
                            if(Judge(tmp,now[j]))
                                ans=i;
                        }
                    }
                }
            }
        }
        if(!ans) puts("Draw");
        else
        {
            int v;
            if(ans%2) v=2;
            else v=1;
            printf("Player %d wins on move %d\n",v,ans);
        }
    }
    return 0;
}


 

你可能感兴趣的:(模拟,判重)