社区讨论

博弈论小白玄关0pts求调

P10501Cutting Game参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mm38bhc1
此快照首次捕获于
2026/02/26 16:56
上周
此快照最后确认于
2026/02/26 20:52
上周
查看原帖
CPP
#include <bits/stdc++.h>

using namespace std;

const int N = 210, inf = 1 << 30;
int n, m, sg[N][N];

inline vector<int> update(int h, int w);

inline int mex(vector<int> v) {
	v.push_back(inf);
	int l = v.size();
	if (v[0] != 0)
		return 0;
	for (int i = 0; i < l - 1; i++) if (v[i] + 1 != v[i + 1])
		return v[i] + 1;
}

inline int SG(int h, int w) {
	if (sg[h][w] > -1)
		return sg[h][w];
	if ((h == 2 && w == 2) || (h == 2 && w == 3) || (h == 3 && w == 2))
		return sg[h][w] = 0;
	if (h == 1 || w == 1)
		return sg[h][w] = 1;
	return sg[h][w] = mex(update(h, w));
}

inline vector<int> update(int h, int w) {
	vector<int> v;
	for (int i = 1; i < h; i++)
		v.push_back(SG(i, w) ^ SG(h - i, w));
	for (int i = 1; i < w; i++)
		v.push_back(SG(h, i) ^ SG(h, w - i));
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	return v;
}

inline void solve() {
	printf("%s\n", SG(n, m) > 1 ? "WIN" : "LOSE");
}

int main() {
	memset(sg, 255, sizeof(sg));
	for (; ~scanf("%d%d", &n, &m); )
		solve();
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...