当前位置:网站首页>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 
边栏推荐
- Is it impossible for lamda to wake up?
- 【LeetCode】Day94-重塑矩阵
- Applicable to Net free barcode API [off] - free barcode API for NET [closed]
- 3. Oracle control file management
- Winter messenger 2
- Open source storage is so popular, why do we insist on self-development?
- One question per day 1020 Number of enclaves
- Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
- Sqlmap tutorial (1)
- Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
猜你喜欢

MySQL advanced part 2: SQL optimization

Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software

Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations

Leetcode stack related

Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter

MySQL advanced part 2: the use of indexes

Real time clock (RTC)

论文阅读报告

Doing SQL performance optimization is really eye-catching

容斥原理 AcWing 890. 能被整除的数
随机推荐
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
5.Oracle-錶空間
Groupbykey() and reducebykey() and combinebykey() in spark
11-gorm-v2-03-basic query
Quickly use Amazon memorydb and build your own redis memory database
Leetcode-3: Longest substring without repeated characters
[leetcode] day95 effective Sudoku & matrix zeroing
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
11-gorm-v2-02-create data
Doing SQL performance optimization is really eye-catching
Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
Golang uses context gracefully
MPLS experiment
P2575 master fight
Daily question 1189 Maximum number of "balloons"
Winter messenger 2
LeetCode 1200. Minimum absolute difference
2022-5-第四周日报
Dataframe (1): introduction and creation of dataframe
什么是套接字?Socket基本介绍