跳到正文

题解

题解:P10501 Cutting Game

NyaingCBC约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年5月29日
更新
2026年5月29日
篇幅
约 2 分钟
获赞
1
题目
P10501

版本

  1. v1当前

同这题。

sg 函数模板题。对每一种大小的纸片求出 sg 函数值即可。需要分成横竖两个方向进行分别求值,最后综合起来求 mex。

不知道 sg 函数的人戳这里。

代码如下:

C++
#include<bits/stdc++.h>
#include<unordered_set>
using namespace std;
int n, m, gf[205][205];
inline int sg(int a, int b) {
	if (gf[a][b] != -1) return gf[a][b];
	unordered_set<int>us;
	for (int i = 2; i < a - 1; ++i)
		us.insert(sg(i, b) ^ sg(a - i, b));
	for (int i = 2; i < b - 1; ++i)
		us.insert(sg(a, i) ^ sg(a, b - i));
	for (int i = 0;; ++i) if (!us.count(i)) return gf[a][b] = i;
}
int main(){
	ios::sync_with_stdio(0);
	memset(gf, -1, sizeof gf);
	while (cin >> n >> m) puts(sg(n, m) ? "WIN" : "LOSE");
	return 0;
}
原文