World of Darkraft CodeForces - 138D (博弈 棋盘翻转)

题目

https://vjudge.net/problem/CodeForces-138D

题意

n * m 的棋盘,每个点都是L, R, X三者之一,两个人轮流选择没有被激光摧毁过的点,
L:往左下,右上发射激光
R:往左上,右下发射激光
X:往左上,左下,右上,右下发射激光。
最后不能选的人输。

思路

顺时针翻转棋盘45° 游戏就成了矩形分成两个或四个矩形的子游戏

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 50;
int n,m;
int sg[N][N][N][N][2];
char mp[N][N];

int get_sg(int x1,int y1,int x2,int y2,int op)
{

    if(sg[x1][y1][x2][y2][op] != -1) return sg[x1][y1][x2][y2][op];int vis[100];
    memset(vis,0,sizeof(vis));
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < m;j++)
        {

            if(((i+j)&1) != op) continue;
            int x = i-j+m,y = i+j;
            if(x<x1||x>x2||y<y1||y>y2) continue;
            int sgg = 0;
            if(mp[i][j] == 'L')
            {
                sgg = get_sg(x1, y1, x2, y-1, op) ^ get_sg(x1, y+1, x2, y2, op);
            }
            else if(mp[i][j] == 'R')
            {
                sgg = get_sg(x1, y1, x-1, y2, op) ^ get_sg(x+1, y1, x2, y2, op);
            }
            else if(mp[i][j] == 'X')
            {
                sgg = get_sg(x1, y1, x-1, y-1, op) ^ get_sg(x1, y+1, x-1, y2, op) ^
                    get_sg(x+1, y1, x2, y-1, op) ^  get_sg(x+1, y+1, x2, y2, op);
            }
            vis[sgg] = 1;
        }
    }
    for(int i = 0;;i++)
    {
        if(vis[i] == 0)
        {
            sg[x1][y1][x2][y2][op] = i;
            return i;
        }
    }
}

int main()
{
scanf("%d%d",&n,&m);
        memset(sg,-1,sizeof(sg));
        for(int i = 0;i < n;i++)
        {
            scanf("%s",mp[i]);
        }
        int ans = get_sg(0,0,n+m-1,n+m-1,0) ^ get_sg(0,0,n+m-1,n+m-1,1);
        if(ans) printf("WIN\n");
        else printf("LOSE\n");

    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值