AcWing 219. 剪纸游戏
原题链接
中等
作者:
鹤唳
,
2021-08-05 14:26:16
,
所有人可见
,
阅读 357
C++ 代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 222;
int SG[N][N];
bool sol[N][N];
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;
}
王丞一yyds