uva 141

题意:往一个棋盘中放入棋子,或拿走棋子,如果当棋盘上的棋子摆放情况(旋转90度,150度,180度)出现过,那么他就输了,我们用set储存情况,但我们不是储存数字,所以我们要重载小于号
#include <iostream>
#include <cstdio>
#include <set>
#include <cstring>
using namespace std;
const int MAXN = 100;

struct Type
{
    bool k[MAXN][MAXN];
};
int n;

bool operator <(const Type &a,const Type &b)
{
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (a.k[i][j] < b.k[i][j])
                return true;
            else if (a.k[i][j] > b.k[i][j])
                return false;
    return false;
}

void change(Type &a)
{
    Type temp;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            temp.k[j][n-i+1] = a.k[i][j];   //比如第一列的数变成了第一行,然后顺序是颠倒的
    a = temp;
}

int main()
{
    while (scanf("%d",&n) != EOF && n)
    {
        set<Type>used;
        Type g;
        memset(g.k,false,sizeof(bool)*MAXN*MAXN);
        int ans = -1;

        for (int i = 1; i <= 2*n; i++)
        {
            int x,y;
            char ch;
            scanf("%d%d %c",&x,&y,&ch);
            
            if (ans != -1)
                continue;

            if (ch == '+')
                g.k[x][y] = true;
            else g.k[x][y] = false;

            if (used.count(g))
            {
                ans = i;
                continue;
            }
            
            Type t(g);
            for (int j = 1; j <= 4; j++)
            {
                used.insert(t);
                change(t);
            }    
        }

        if (ans == -1)
            printf("Draw\n");
        else if (ans & 1)
            printf("Player 2 wins on move %d\n",ans);
        else printf("Player 1 wins on move %d\n",ans);
    }
    return 0;
}


你可能感兴趣的:(uva 141)