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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值