当前位置:网站首页>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 
边栏推荐
- Open source storage is so popular, why do we insist on self-development?
- Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
- Leetcode divide and conquer / dichotomy
- [2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
- Sum of three terms (construction)
- There are three kinds of SQL connections: internal connection, external connection and cross connection
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- Client use of Argo CD installation
- Bit of MySQL_ OR、BIT_ Count function
- Redis-01.初识Redis
猜你喜欢

中国剩余定理 AcWing 204. 表达整数的奇怪方式

Matrixdb V4.5.0 was launched with a new mars2 storage engine!

4. Oracle redo log file management

Chapter 6 relational database theory

MySQL advanced part 1: View

Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a

Groupbykey() and reducebykey() and combinebykey() in spark

栈 AcWing 3302. 表达式求值

7.Oracle-表结构

There are three kinds of SQL connections: internal connection, external connection and cross connection
随机推荐
[rust notes] 17 concurrent (Part 2)
FFmpeg build下载(包含old version)
LeetCode 0107. Sequence traversal of binary tree II - another method
[wustctf2020] plain_ WP
Leetcode-1200: minimum absolute difference
容斥原理 AcWing 890. 能被整除的数
博弈论 AcWing 891. Nim游戏
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
One question per day 1020 Number of enclaves
Leetcode-556: the next larger element III
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
MySQL advanced part 1: stored procedures and functions
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
1.13 - RISC/CISC
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
Chapter 6 relational database theory
Traversal of leetcode tree
Filter the numbers and pick out even numbers from several numbers
International Open Source firmware Foundation (osff) organization
Client use of Argo CD installation