当前位置:网站首页>Game theory acwing 893 Set Nim game
Game theory acwing 893 Set Nim game
2022-07-05 06:24: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
边栏推荐
- Client use of Argo CD installation
- MySQL advanced part 1: triggers
- C - XOR to all (binary topic)
- ollvm编译出现的问题纪录
- Presentation of attribute value of an item
- 栈 AcWing 3302. 表达式求值
- LeetCode-54
- 阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
- Leetcode stack related
- Leetcode-6110: number of incremental paths in the grid graph
猜你喜欢
背包问题 AcWing 9. 分组背包问题
博弈论 AcWing 892. 台阶-Nim游戏
5. Oracle TABLESPACE
Sqlmap tutorial (II) practical skills I
Paper reading report
3. Oracle control file management
WordPress switches the page, and the domain name changes back to the IP address
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
Leetcode-6111: spiral matrix IV
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
随机推荐
Liunx starts redis
Sum of three terms (construction)
Simple selection sort of selection sort
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
MySQL advanced part 1: View
Leetcode-1200: minimum absolute difference
背包问题 AcWing 9. 分组背包问题
ollvm编译出现的问题纪录
Groupbykey() and reducebykey() and combinebykey() in spark
AE tutorial - path growth animation
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
Shutter web hardware keyboard monitoring
Leetcode-3: Longest substring without repeated characters
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
[rust notes] 15 string and text (Part 1)
[rust notes] 14 set (Part 1)
LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
Winter messenger 2