当前位置:网站首页>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 
边栏推荐
- NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
- 求组合数 AcWing 889. 满足条件的01序列
- LeetCode-61
- [rust notes] 17 concurrent (Part 1)
- LeetCode-54
- Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
- AE tutorial - path growth animation
- Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
- RecyclerView的应用
- __ builtin_ Popcount() counts the number of 1s, which are commonly used in bit operations
猜你喜欢

MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理

MySQL advanced part 2: SQL optimization

Real time clock (RTC)

5. Oracle tablespace

【LeetCode】Easy | 20. Valid parentheses

4.Oracle-重做日志文件管理

阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队

Error ora-28547 or ora-03135 when Navicat connects to Oracle Database

Traditional databases are gradually "difficult to adapt", and cloud native databases stand out

Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
随机推荐
MPLS experiment
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?
Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
求组合数 AcWing 888. 求组合数 IV
如何正确在CSDN问答进行提问
1.14 - assembly line
4. 对象映射 - Mapping.Mapster
Leetcode backtracking method
Presentation of attribute value of an item
在新线程中使用Handler
Leetcode-6110: number of incremental paths in the grid graph
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
求组合数 AcWing 887. 求组合数 III
Leetcode-6109: number of people who know secrets
P2575 master fight
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
Daily question 1189 Maximum number of "balloons"
Ffmpeg build download (including old version)
【LeetCode】Day94-重塑矩阵
Record the process of configuring nccl and horovod in these two days (original)