当前位置:网站首页>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
边栏推荐
- [rust notes] 17 concurrent (Part 1)
- Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
- Modnet matting model reproduction
- 1.13 - RISC/CISC
- 1.14 - assembly line
- Leetcode dynamic programming
- [rust notes] 16 input and output (Part 2)
- 4. Object mapping Mapster
- MySQL advanced part 1: triggers
- [leetcode] day95 effective Sudoku & matrix zeroing
猜你喜欢
Leetcode-6111: spiral matrix IV
求组合数 AcWing 887. 求组合数 III
P2575 master fight
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
Sqlmap tutorial (II) practical skills I
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
求组合数 AcWing 888. 求组合数 IV
LeetCode-61
随机推荐
Find the combination number acwing 887 Find combination number III
Redis-02.Redis命令
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
[rust notes] 17 concurrent (Part 2)
Simple selection sort of selection sort
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
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
求组合数 AcWing 889. 满足条件的01序列
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
[rust notes] 16 input and output (Part 1)
Presentation of attribute value of an item
7.Oracle-表结构
Leetcode recursion
[2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
[learning] database: several cases of index failure
P2575 master fight
Redis publish subscribe command line implementation
在新线程中使用Handler
博弈论 AcWing 891. Nim游戏
【LeetCode】Day94-重塑矩阵