当前位置:网站首页>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
边栏推荐
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- Day 2 document
- Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
- One question per day 1020 Number of enclaves
- JS quickly converts JSON data into URL parameters
- 2048项目实现
- 阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
- [BMZCTF-pwn] ectf-2014 seddit
- How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
- Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
猜你喜欢
4.Oracle-重做日志文件管理
Leetcode-6110: number of incremental paths in the grid graph
Leetcode stack related
博弈论 AcWing 894. 拆分-Nim游戏
How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
Paper reading report
Doing SQL performance optimization is really eye-catching
什么是套接字?Socket基本介绍
高斯消元 AcWing 884. 高斯消元解异或線性方程組
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
随机推荐
中国剩余定理 AcWing 204. 表达整数的奇怪方式
Leetcode divide and conquer / dichotomy
P2575 master fight
4. Oracle redo log file management
Quickly use Amazon memorydb and build your own redis memory database
Liunx starts redis
MySQL advanced part 2: SQL optimization
Chapter 6 relational database theory
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
7.Oracle-表结构
Leetcode-6111: spiral matrix IV
International Open Source firmware Foundation (osff) organization
求组合数 AcWing 888. 求组合数 IV
June 29, 2022 daily
New title of module a of "PanYun Cup" secondary vocational network security skills competition
[rust notes] 17 concurrent (Part 1)
Basic explanation of typescript
LeetCode-54
WordPress switches the page, and the domain name changes back to the IP address
1.手动创建Oracle数据库