SCUT - 290 - PARCO的因数游戏 - 博弈论
2024-09-06 05:47:21
https://scut.online/p/290
一个 N 个数的取数游戏,Kaildls 和 Parco 轮流操作,每次操作从 N 个数中取一个数 y 并把他变成 y-x(满足 x | y 且x < y),无法操作的人输。
假设 Kaildls 先手且两人都是用最优策略,请问最后谁会赢?
第一次学SG函数,要找的是每次能从石子堆中取走的数目,记录下来。
最后的Nim和为0是后手赢?
#include<bits/stdc++.h>
using namespace std;
#define ll long long #define MAXN 1000005
#define N 1000005 //f[N]:可改变当前状态的方式,N为方式的种类,f[N]要在getSG之前先预处理
//SG[]:0~n的SG函数值
//S[]:为x后继状态的集合
vector<int> nextofSG[MAXN];
int f[N],SG[MAXN],S[MAXN];
void getSG(int n){
for(int i = ; i <= n; i++){
int l=nextofSG[i].size();
//后继状态 最多有l 种
for(int j=;j<=l;j++){
S[j]=;
}
for(auto vi:nextofSG[i]){
//vi:从i状态能取走的石子数
S[SG[i-vi]]=;
}
for(int j=;j<=l;j++){
if(!S[j]){
SG[i] = j;
break;
}
}
//cout<<"SG["<<i<<"]="<<SG[i]<<endl;
} } int a[]; unsigned generateai(unsigned &n,unsigned &x,unsigned &y, unsigned &z){
x=x^(x<<);
x=x^(x>>);
x=x^(x<<);
x=x^(x>>);
unsigned w=x^(y^z);
x=y;
y=z;
z=w;
return z;
} int main(){
unsigned n,x,y,z;
for(int i=;i<=;i++){
for(int j=i+i;j<=;j+=i){
nextofSG[j].push_back(i);
}
}
getSG();
for(int t=;t<;t++){
cin>>n>>x>>y>>z;
int sumSG=;
for(int i=;i<n;i++){
a[i]=generateai(n,x,y,z)%n+;
//cout<<a[i]<<endl;
sumSG^=SG[a[i]];
}
//cout<<"!"<<sumSG<<endl;
if(sumSG==)
cout<<"Parco"<<endl;
else{
cout<<"Kaildls"<<endl;
}
}
}
最新文章
- JSP复习整理(一)表单
- 如何让UIView中的Button点击之后跳转到另一个ViewController上去,ViewController上也有一个按钮 可以返回
- 关于普通定时器与高级定时器的 PWM输出的初始化的区别
- sass的四种css编译风格
- 【iOS】线程安全的文件读写
- Linux 文件操作总结
- Flume Hello World!
- Oracle一些常用的查询命令总结(持续更新)
- 如何给div加一个边框border样式
- HDU 4717The Moving Points warmup2 1002题(三分)
- .NET开发面向对象1
- nodejs爬虫初试---superagent和cheerio
- kafka HA
- .NET Core 指南 官方
- u-boot之start_armboot函数分析
- linux(乌班图)下执行pip没有问题,执行sudo pip报错的问题
- 128. Longest Consecutive Sequence最长连续序列
- JDBC程序优化--提取配置信息放到属性文件中
- Docker Manager for Docker Swarm deploy
- nodejs 前端工具总结
热门文章
- 杭电1863 畅通project
- hdu 5338 ZZX and Permutations (贪心+线段树+二分)
- MongoDB---出现no write has been done on this connection解决方式
- HTML5开发移动web应用—JQuery Mobile(2)-导航栏和页脚
- Golang之bytes.buffer
- [UnityShader3]溶解与重现效果
- Struts2+Spring+Hibernate step by step 04 整合Spring之二,从数据库验证username和password
- POJ 2524 Ubiquitous Religions (幷查集)
- 利用python暴力破解ssh
- fatal error C1083: 无法打开预编译头文件:“Debug\opencv.pch”: No such file or directory