当前位置:网站首页>博弈论 AcWing 893. 集合-Nim游戏
博弈论 AcWing 893. 集合-Nim游戏
2022-07-27 10:35: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");
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.
- Use of pyquery
- 2022牛客多校 (3)J.Journey
- 01 BTC cryptology principle
- img src为空或者src不存在,图片出现白色边框
- IMG SRC is empty or SRC does not exist, and the picture has a white border
- ACM warm-up Exercise 2 in 2022 summer vacation (summary)
- Non progressive phenomena of entropy and morphology
- 10 complete half of the questions
- How to create a.Net image with diagnostic tools
猜你喜欢

The difference of iteration number and information entropy

Use of beautifulsoup

A verification test of the relationship between iteration number and entropy

How to build a data index system is the most effective. It will take you a quick start from 0 to 1

Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!

最长上升子序列模型 AcWing 1010. 拦截导弹

2022牛客多校 (3)J.Journey

Digital triangle model acwing 275. pass note

Budweiser, a well-known beer, plans to launch NFT in an attempt to unveil the "long planned" uplink?

荒野觅踪---寻找迭代次数
随机推荐
Learning notes - wechat payment
Yum source installation
Neural network learning notes
Tree data conversion
pyquery 的使用
[FPGA tutorial case 40] communication case 10 -- Verilog implementation of a simple OFDM system based on FPGA
Chunjun supports DDL conversion and automatic execution of heterogeneous data sources - dtmo 02 review (including course playback + courseware)
A verification test of the relationship between iteration number and entropy
Wilderness search --- search iterations
tensorflow运行报错解决方法
最短移动距离和形态复合体的熵
The influence of the number of non-zero values in the picture on Classification
A measurement method of 5g air interface one-way delay and its reliability
背包模型 AcWing 423. 采药
Background color style modification on table hover in antd
img src为空或者src不存在,图片出现白色边框
Play with the cluster configuration center and learn about the Taier console
How to build a real-time development platform to deeply release the value of enterprise real-time data?
洛谷P1441 砝码称重
Learning notes - simple server implementation