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