【POJ3480】John 博弈 Anti-SG misère规则尼姆游戏

转载请注明出处:http://blog.csdn.net/vmurder/article/details/42671843

其实我就是觉得原创的访问量比未授权盗版多有点不爽233。。。

题意:跟NIM游戏差不多,不过是谁不能操作了,谁赢。

定理:

NIM游戏规则取最后一个石子输

适用范围:对于任意一个Anti-SG

游戏,当局面中所有的单一游戏

的SG值为0时,游戏结束。

(1)SG==0,有某单一游戏的SG>1。(败)

(2)SG!=0,有某单一游戏的SG>1。(胜)

(3)SG==0,无某单一游戏的SG>1。(胜)

(4)SG!=0,无某单一游戏的SG>1。(败)

代码:

#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

int main()

{

int T,n,sg,x,k;

for(scanf("%d",&T);T--;)

{

scanf("%d",&n);

for(k=sg=0;n--;)

{

scanf("%d",&x);

k^=x,sg=max(sg,x);

}

if(k){

if(sg>1)puts("John");

else puts("Brother");

}

else {

if(sg<2)puts("John");

else puts("Brother");

}

}

return 0;

}

时间: 2024-10-24 08:37:45

【POJ3480】John 博弈 Anti-SG misère规则尼姆游戏的相关文章

一次失败的刷题经历:[LeetCode]292之尼姆游戏(Nim Game)

最近闲来无事刷LeetCode,发现这道题的Accept Rate还是挺高的,尝试着做了一下,结果悲剧了,把过程写下来,希望能长点记性.该题的描述翻译成中文如下: 你正在和你的朋友玩尼姆游戏(Nim Game): 桌子上有一堆石块,你和你的朋友轮流去拿这些石块,每次只能拿1块.2块或者3块.在石块被拿光前,最后一次拿到石块的人获胜.你将首先去拿这些石块. 你和你的朋友都非常聪明,并且拥有应对该游戏的最佳策略.写一个函数来决定在给定石块数量的情况下,你是否能够获胜.比如:如果桌子上有4块石块,那么

nyoj 就拿石头(三)(尼姆游戏定理的使用)

就拿石头(三) 时间限制:1000 ms |  内存限制:1000 KB 难度:6 描写叙述 小王喜欢与同事玩一些小游戏,今天他们选择了玩取石子. 游戏规则例如以下:共同拥有N堆石子,已知每堆中石子的数量,两个人轮流取子,每次仅仅能选择N堆石子中的一堆,取一定数量的石子(最少取一个),取过子之后.还能够将该堆石子中剩下的随意多个石子中随意选取几个放到其他的随意一堆或几堆上. 等哪个人无法取子时就表示此人输掉了游戏. 注意,一堆石子没有子之后.就不能再往此处放石子了. 如果每次都是小王先取石子,而

[LeetCode] Nim Game 尼姆游戏

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove th

[LeetCode]-292. Nim Game(Easy)(C + 尼姆游戏)

292. Nim Game My Submissions Question Editorial Solution Total Accepted: 67907 Total Submissions: 128306 Difficulty: Easy You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns

[hdu-5795]A Simple Nim 博弈 尼姆博弈 SG函数打表找规律

[题目]题目链接 Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed).To make the game more int

HDU5014 Game(尼姆博弈)

Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 493    Accepted Submission(s): 380 Problem Description Here is a game for two players. The rule of the game is described below: ● In the beg

Being a Good Boy in Spring Festival(尼姆博弈)

Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 51 Accepted Submission(s): 45   Problem Description 一年在外 父母时刻牵挂春节回家 你能做几天好孩子吗寒假里尝试做做下面的事情吧 陪妈妈逛一次菜场悄悄给爸爸买个小礼物主动地

HDU 4315 Climbing the Hill (尼姆博弈)

Climbing the Hill Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description Alice and Bob are playing a game called "Climbing the Hill". The game board consists of cells arranged vertically, as the

hdu-------(1848)Fibonacci again and again(sg函数版的尼姆博弈)

Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5088    Accepted Submission(s): 2126 Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F(2)=2;