PE 301 Nim (Nim博弈)
来源:互联网 发布:软件安全在线检测 编辑:程序博客网 时间:2024/06/05 06:03
Nim
Problem 301
Nim is a game played with heaps of stones, where two players take it in turn to remove any number of stones from any heap until no stones remain.
We'll consider the three-heap normal-play version of Nim, which works as follows:
- At the start of the game there are three heaps of stones.
- On his turn the player removes any positive number of stones from any single heap.
- The first player unable to move (because no stones remain) loses.
If (n1,n2,n3) indicates a Nim position consisting of heaps of size n1, n2 and n3 then there is a simple function X(n1,n2,n3) — that you may look up or attempt to deduce for yourself — that returns:
- zero if, with perfect strategy, the player about to move will eventually lose; or
- non-zero if, with perfect strategy, the player about to move will eventually win.
For example X(1,2,3) = 0 because, no matter what the current player does, his opponent can respond with a move that leaves two heaps of equal size, at which point every move by the current player can be mirrored by his opponent until no stones remain; so the current player loses. To illustrate:
- current player moves to (1,2,1)
- opponent moves to (1,0,1)
- current player moves to (0,0,1)
- opponent moves to (0,0,0), and so wins.
For how many positive integers n ≤ 230 does X(n,2n,3n) = 0 ?
题意:取石子游戏。
有多少个正整数n ≤ 230使得X(n,2n,3n) = 0?
题解:典型的Nim博弈...
代码:
#include<bits/stdc++.h>using namespace std;typedef long long ll;int main(){ ll a,b,c; ll count=0;for(int i=1;i<=(1<<30);i++){a=i;b=2*i;c=3*i;ll res=a ^ b^ c;if(res==0)count++; } cout<<count<<endl; return 0;}
- PE 301 Nim (Nim博弈)
- Nim(Nim博弈变形)
- Misere Nim (Nim博弈)
- poj2975 nim(nim博弈)
- [POJ](2975)Nim ---Nim博弈(博弈)
- 【POJ2975】Nim (博弈)
- 博弈(一)Nim
- hdu1907(Nim博弈)
- Lightoj1253(博弈+NIM)
- Lightoj1393(博弈+NIM)
- HDU2176(Nim博弈)
- Poj2975(NIM博弈)
- POJ 2975 Nim(nim博弈)
- POJ-2975-Nim(Nim博弈)
- (博弈Nim)Nim
- nim 博弈
- Nim博弈
- Nim博弈
- linux install mysql
- 包含RecyclerView的module导入项目出现的问题
- 面对机会,最缺的是把握
- SQLite导出整个数据库/导出某个表到SQL文件
- new operator,operator new and replacement new
- PE 301 Nim (Nim博弈)
- leetcode 404 Sum of Left Leaves C++
- 最大连续字段和
- “Microsoft Office Professional Plus 2010在安装中出错”解决办法
- Canvas实现拖拽放大镜
- 回归
- JavaScript 鼠标划入划出
- 折半插入排序,插入排序
- Python学习笔记--正则表达式篇