当前位置:网站首页>博弈论 AcWing 893. 集合-Nim游戏
博弈论 AcWing 893. 集合-Nim游戏
2022-07-05 06:16:00 【T_Y_F666】
博弈论 AcWing 893. 集合-Nim游戏
原题链接
算法标签
数学知识 博弈论 SG函数
思路
若只有一堆石子 SG函数计算
结论
对于多堆石子
SG函数值等于它包含的各个子游戏SG函数值的异或和,即:SG(G) = SG(G1) ^ SG(G2) ^ … ^ SG(Gm),若SG(G)为0, 则必胜, 否则, 必败
其他概念
代码
#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 s[N], f[M];
int k, 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){
// f[x]是否已被计算
if(f[x]!=-1){
return f[x];
}else{
// 存储当前局面可以到达的局面
unordered_set<int> S;
rep(i, 0, k){
if(x>=s[i]){
S.insert(sg(x-s[i]));
}
}
// 查找集合中不存在的最小自然数
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);
k=read();
rep(i, 0, k){
s[i]=read();
}
n=read();
memset(f, -1, sizeof f);
int ans=0;
rep(i, 0, n){
int x=read();
ans^=sg(x);
}
if(ans){
puts("Yes");
}else{
puts("No");
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}
- 可变电阻器概述——结构、工作和不同应用
- 927. 三等分 模拟
- Multi screen computer screenshots will cut off multiple screens, not only the current screen
- Introduction to LVS [unfinished (semi-finished products)]
- 【Rust 笔记】14-集合(下)
- Real time clock (RTC)
- 11-gorm-v2-03-basic query
- 一些工具的记录2022
- js快速将json数据转换为url参数
猜你喜欢
Liunx starts redis
MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
Leetcode-6110: number of incremental paths in the grid graph
Arduino 控制的 RGB LED 无限镜
Data visualization chart summary (I)
开源存储这么香,为何我们还要坚持自研?
4. 对象映射 - Mapping.Mapster
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
LeetCode-61
随机推荐
LeetCode 0108.将有序数组转换为二叉搜索树 - 数组中值为根,中值左右分别为左右子树
leetcode-6108:解密消息
1.14 - assembly line
SQLMAP使用教程(一)
Leetcode-6108: decrypt messages
Currently clicked button and current mouse coordinates in QT judgment interface
MySQL advanced part 1: stored procedures and functions
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
Data visualization chart summary (I)
C Primer Plus Chapter 15 (bit operation)
How to understand the definition of sequence limit?
1.13 - RISC/CISC
Leetcode-1200: minimum absolute difference
LeetCode-61
2021apmcm post game Summary - edge detection
LeetCode 0107. Sequence traversal of binary tree II - another method
1039 Course List for Student
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
1.15 - input and output system
Daily question 1984 Minimum difference in student scores