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;
}
}
}

最新文章

  1. JSP复习整理(一)表单
  2. 如何让UIView中的Button点击之后跳转到另一个ViewController上去,ViewController上也有一个按钮 可以返回
  3. 关于普通定时器与高级定时器的 PWM输出的初始化的区别
  4. sass的四种css编译风格
  5. 【iOS】线程安全的文件读写
  6. Linux 文件操作总结
  7. Flume Hello World!
  8. Oracle一些常用的查询命令总结(持续更新)
  9. 如何给div加一个边框border样式
  10. HDU 4717The Moving Points warmup2 1002题(三分)
  11. .NET开发面向对象1
  12. nodejs爬虫初试---superagent和cheerio
  13. kafka HA
  14. .NET Core 指南 官方
  15. u-boot之start_armboot函数分析
  16. linux(乌班图)下执行pip没有问题,执行sudo pip报错的问题
  17. 128. Longest Consecutive Sequence最长连续序列
  18. JDBC程序优化--提取配置信息放到属性文件中
  19. Docker Manager for Docker Swarm deploy
  20. nodejs 前端工具总结

热门文章

  1. 杭电1863 畅通project
  2. hdu 5338 ZZX and Permutations (贪心+线段树+二分)
  3. MongoDB---出现no write has been done on this connection解决方式
  4. HTML5开发移动web应用—JQuery Mobile(2)-导航栏和页脚
  5. Golang之bytes.buffer
  6. [UnityShader3]溶解与重现效果
  7. Struts2+Spring+Hibernate step by step 04 整合Spring之二,从数据库验证username和password
  8. POJ 2524 Ubiquitous Religions (幷查集)
  9. 利用python暴力破解ssh
  10. fatal error C1083: 无法打开预编译头文件:“Debug\opencv.pch”: No such file or directory