AcWing 219. 剪纸游戏
原题链接
中等
作者:
冬月悠悠
,
2021-08-05 14:13:53
,
所有人可见
,
阅读 313
#include <bits/stdc++.h>
int SG[222][222];
bool sol[222][222];
int sg(int x, int y)
{
if (sol[x][y])
{
return SG[x][y];
}
if (x == 1 && y == 1)
{
return sol[x][y] = 1;
SG[x][y] = 0;
}
bool _[500] = {0};
for (int i = 2; i < x - 1; i ++)
{
_[sg(i, y) ^ sg(x - i, y)] = 1;
}
for (int i = 2; i < y - 1; i ++)
{
_[sg(x, y - i) ^ sg(x, i)] = 1;
}
int p = 0;
while (_[p])
{
++ p;
}
return sol[x][y] = 1, SG[x][y] = p;
}
int main()
{
int x, y;
while (~ scanf("%d%d", &x, &y))
{
puts(sg(x, y) ? "WIN" : "LOSE");
}
return 0;
}