当前位置:网站首页>Game theory acwing 893. Set Nim game
Game theory acwing 893. Set Nim game
2022-07-27 11:19:00 【T_ Y_ F666】
Game theory AcWing 893. aggregate -Nim game
Original link
AcWing 893. aggregate -Nim game
Algorithm tags
Math knowledge Game theory SG function
Ideas
If there is only a pile of stones SG Function calculation 
Conclusion 
For multiple heaps of stones
SG The value of the function is equal to each sub game it contains SG The exclusive or sum of function values , namely :SG(G) = SG(G1) ^ SG(G2) ^ … ^ SG(Gm), if SG(G) by 0, You will win , otherwise , You will lose 
Other concepts 
Code
#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] Has it been calculated
if(f[x]!=-1){
return f[x];
}else{
// Store the current situation and the situation that can be reached
unordered_set<int> S;
rep(i, 0, k){
if(x>=s[i]){
S.insert(sg(x-s[i]));
}
}
// Find the minimum natural number that does not exist in the set
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");
}
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- Solve importerror: cannot import name'abs'import tensorflow error
- Redis+caffeine two-level cache enables smooth access speed
- [shader realizes shake random shaking effect _shader effect Chapter 10]
- 状态压缩DP AcWing 91. 最短Hamilton路径
- Use of parsel
- 区间问题 AcWing 906. 区间分组
- FAQs of "relay chain" and "dot" in Poka ecosystem
- Description and feelings
- 【着色器实现Shake随机摇动效果_Shader效果第十篇】
- Luogu p1896 non aggression
猜你喜欢

背包模型 AcWing 1024. 装箱问题

49字母异位分组和242有效的字母异位词

背包模型 AcWing 1022. 宠物小精灵之收服

Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?

A verification test of the relationship between iteration number and entropy

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

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

区间问题 AcWing 906. 区间分组

Kangaroo cloud stack based on CBO in spark SQL optimization

数字三角形模型 AcWing 1027. 方格取数
随机推荐
Budweiser, a well-known beer, plans to launch NFT in an attempt to unveil the "long planned" uplink?
[shader realizes shake random shaking effect _shader effect Chapter 10]
泰山OFFICE技术讲座:缩放比例与打开文件
How to create a.Net image with diagnostic tools
深析C语言的灵魂 -- 指针
洛谷 P3052 [USACO12MAR]Cows in a Skyscraper G
Miscellaneous records of Finance
Cancer DDD
IO流_字符流、IO流小结、IO流案例总结
What is the issuing price of NFT (Interpretation of NFT and establishment of NFT world outlook)
Antd table+checkbox default value display
Tree data conversion
【FPGA教程案例40】通信案例10——基于FPGA的简易OFDM系统verilog实现
2022 Niuke multi school (3) j.journey
Backpack model acwing 1022. Collection of pet elves
Students, don't copy all my code, remember to change it, or we both want G
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
SQL Server2000 database error
01 BTC cryptology principle
The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence