[AcWing 894] 拆分-Nim游戏
作者:互联网
点击查看代码
#include<iostream>
#include<cstring>
#include<unordered_set>
using namespace std;
const int N = 110;
int n;
int f[N];
int sg(int x)
{
if (f[x] != -1) return f[x];
unordered_set<int> S;
for (int i = 0; i < x; i ++)
// 避免重复
for (int j = 0; j <= i; j ++)
S.insert(sg(i) ^ sg(j));
for (int i = 0; ; i ++)
if (!S.count(i))
return f[x] = i;
}
int main()
{
cin >> n;
memset(f, -1, sizeof f);
int res = 0;
for (int i = 0; i < n; i ++) {
int x;
cin >> x;
res ^= sg(x);
}
if (res) puts("Yes");
else puts("No");
return 0;
}
- 和集合 Nim 游戏类似,不同的是 $ SG(b_1, b_2) = SG(b_1) \oplus SG(b_2) $
标签:894,puts,Nim,int,res,return,include,SG,AcWing 来源: https://www.cnblogs.com/wKingYu/p/16275406.html