当前位置:网站首页>博弈论 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");
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
- 【LeetCode】Easy | 20. Valid parentheses
- leetcode-556:下一个更大元素 III
- Liunx starts redis
- MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
- [rust notes] 17 concurrent (Part 1)
- Navicat连接Oracle数据库报错ORA-28547或ORA-03135
- Redis publish subscribe command line implementation
- SPI details
- 2022年貴州省職業院校技能大賽中職組網絡安全賽項規程
猜你喜欢
随机推荐
Binary search template
leetcode-31:下一个排列
Leetcode array operation
[leetcode] day94 reshape matrix
leetcode-6108:解密消息
Traversal of leetcode tree
927. Trisection simulation
1040 Longest Symmetric String
C - XOR to all (binary topic)
Doing SQL performance optimization is really eye-catching
11-gorm-v2-03-basic query
Multi screen computer screenshots will cut off multiple screens, not only the current screen
实时时钟 (RTC)
LeetCode 0108.将有序数组转换为二叉搜索树 - 数组中值为根,中值左右分别为左右子树
Arduino 控制的 RGB LED 无限镜
Appium基础 — 使用Appium的第一个Demo
One question per day 1020 Number of enclaves
SPI 详解
【Rust 笔记】15-字符串与文本(上)
JS quickly converts JSON data into URL parameters









