当前位置:网站首页>博弈论 AcWing 894. 拆分-Nim游戏
博弈论 AcWing 894. 拆分-Nim游戏
2022-07-05 06:16:00 【T_Y_F666】
博弈论 AcWing 894. 拆分-Nim游戏
原题链接
算法标签
数学知识 博弈论 SG函数
思路

代码
#include<bits/stdc++.h>
#define int long long
#define abs fabs
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 105, M = 10005;
int f[M];
int n;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
int sg(int x){
if(f[x]!=-1){
return f[x];
}else{
unordered_set<int> S;
// 第一堆数量要求
rep(i, 0, x){
// 第二堆数量要求
rep(j, 0, i+1){
S.insert(sg(i)^sg(j));
}
}
// mex 函数
for(int i=0;;++i){
if(!S.count(i)){
return f[x]=i;
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(f, -1, sizeof f);
n=read();
int ans=0;
while(n--){
int x=read();
ans^=sg(x);
}
if(ans){
puts("Yes");
}else{
puts("No");
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
猜你喜欢
![Introduction to LVS [unfinished (semi-finished products)]](/img/72/d5a943a8d6d71823dcbd7f23dda35b.png)
Introduction to LVS [unfinished (semi-finished products)]

NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar

实时时钟 (RTC)

MySQL advanced part 2: storage engine

Operator priority, one catch, no doubt

1.15 - input and output system

Leetcode array operation

LeetCode 0108.将有序数组转换为二叉搜索树 - 数组中值为根,中值左右分别为左右子树

Spark中groupByKey() 和 reduceByKey() 和combineByKey()

Redis publish subscribe command line implementation
随机推荐
MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
Groupbykey() and reducebykey() and combinebykey() in spark
MySQL advanced part 1: triggers
927. 三等分 模拟
A reason that is easy to be ignored when the printer is offline
【Rust 笔记】13-迭代器(中)
Leetcode-6108: decrypt messages
leetcode-1200:最小绝对差
Leetcode-3: Longest substring without repeated characters
数据可视化图表总结(一)
1.15 - input and output system
1.15 - 输入输出系统
SPI 详解
数据可视化图表总结(二)
1.14 - assembly line
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
4. 对象映射 - Mapping.Mapster
[leetcode] day95 effective Sudoku & matrix zeroing
高斯消元 AcWing 884. 高斯消元解异或线性方程组
[rust notes] 17 concurrent (Part 1)