当前位置:网站首页>Game theory acwing 894 Split Nim game
Game theory acwing 894 Split Nim game
2022-07-05 06:24:00 【T_ Y_ F666】
Game theory AcWing 894. Split -Nim game
Original link
Algorithm tags
Math knowledge Game theory SG function
Ideas

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 f[M];
int 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){
if(f[x]!=-1){
return f[x];
}else{
unordered_set<int> S;
// Quantity requirements for the first pile
rep(i, 0, x){
// Quantity requirements of the second pile
rep(j, 0, i+1){
S.insert(sg(i)^sg(j));
}
}
// mex function
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);
memset(f, -1, sizeof f);
n=read();
int ans=0;
while(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 
边栏推荐
- MySQL advanced part 2: MySQL architecture
- 高斯消元 AcWing 884. 高斯消元解异或线性方程组
- June 29, 2022 daily
- MySQL advanced part 2: SQL optimization
- Simple selection sort of selection sort
- Sum of three terms (construction)
- Golang uses context gracefully
- Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
- [rust notes] 16 input and output (Part 2)
- C - XOR to all (binary topic)
猜你喜欢

栈 AcWing 3302. 表达式求值

LeetCode 0107. Sequence traversal of binary tree II - another method

4. Object mapping Mapster

求组合数 AcWing 887. 求组合数 III

MySQL advanced part 2: the use of indexes

Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
![[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields](/img/65/7fa32cd0005ddaaebacd85c25e0c7e.jpg)
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields

Open source storage is so popular, why do we insist on self-development?

5.Oracle-錶空間

Day 2 document
随机推荐
MySQL advanced part 1: triggers
博弈论 AcWing 894. 拆分-Nim游戏
Is it impossible for lamda to wake up?
MySQL advanced part 1: index
Leetcode divide and conquer / dichotomy
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
[rust notes] 16 input and output (Part 1)
容斥原理 AcWing 890. 能被整除的数
Winter messenger 2
What's wrong with this paragraph that doesn't work? (unresolved)
Traversal of leetcode tree
Leetcode-22: bracket generation
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
Sum of three terms (construction)
Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter
4.Oracle-重做日志文件管理
AE tutorial - path growth animation
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
Leetcode-3: Longest substring without repeated characters
One question per day 1020 Number of enclaves