hdu2176 取(m堆)石子游戏 nim博弈
来源:互联网 发布:linux挂载ntfs u盘 编辑:程序博客网 时间:2024/06/06 12:26
还是nim博弈求先手方案的问题,N堆石子,每次可以选择一堆取走若干个,问先手有多少中取法可以必胜。必胜的话,输出所有方案,即若存在一堆数量为a的石子,取完后还剩下b个可以必胜就输出a b。先取第i堆的话,其他堆异或的结果为B,那么(Ai-x) xor B==0时,说明从Ai中取走x可以留给对手一个必败态,所以对每一堆求出x后,判断一下x是否小于Ai,若小于则答案++,记录下来取法。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef long long ll;int n,m;int a[202000];int b1[202000],b2[202000];int main(){ while(~scanf("%d",&n) && n) { int ans=0,ct=0; for (int i=1; i<=n; i++) scanf("%d",&a[i]),ans^=a[i]; for (int i=1; i<=n; i++) { ans^=a[i]; if (ans<a[i]) { ct++; b1[ct]=a[i]; b2[ct]=ans; } ans^=a[i]; } if (ct) { puts("Yes"); for (int i=1; i<=ct; i++) printf("%d %d\n",b1[i],b2[i]); } else puts("No"); } return 0;}
0 0
- hdu2176 取(m堆)石子游戏 nim博弈
- nim博弈 hdu2176 取(m堆)石子游戏
- hdu2176 取(m堆)石子游戏(nim博弈)
- hdu2176取(m堆)石子游戏 ——Nim 博弈
- HDU2176:取(m堆)石子游戏(Nim)
- HDU2176 取(m堆)石子游戏
- hdu2176 取(m堆)石子游戏
- HDU2176 取(m堆)石子游戏
- hdu2176 取(m堆)石子游戏
- hdu2176 取(m堆)石子游戏
- hdu2176取(m堆)石子游戏
- HDU2176 取(m堆)石子游戏
- HDU2176取(m堆)石子游戏
- hdu2176取(m堆)石子游戏 组合游戏初步——NIM
- hdu 2176 取(m堆)石子游戏(Nim博弈)
- HDU 2176 取(m堆)石子游戏(Nim博弈)
- 博弈论基础 Nim博弈 取(m堆)石子游戏 HDU
- hdu2176取(m堆)石子游戏 nim hdu1848Fibonacci again and again sg
- 移动开发之Xamarin+C#环境搭建
- 南阳理工acm- ASCII码排序 -题目4
- C++ 文件读写示例
- windows/linux部署Solr4.4.0
- php imagemagick 配置
- hdu2176 取(m堆)石子游戏 nim博弈
- 政府必须强制winxp用户更新操作系统,否则可能出现国家灾难,迎来信息末日
- Fedora 安装 vtune amplifier
- VIM OR VI 回顾总结 - crperlin -- 持续更新
- C++ const_cast强制去掉常量属性
- JavaScript实现倒计时效果
- 在C#(C sharp)中数组和集合的区别及他们的初始化器
- hdu1527,poj1067 取石子游戏 威佐夫博奕(Wythoff Game)
- 银行业务调度系统