HDU 5795 A Simple Nim (SG博弈)

网友投稿 246 2022-08-27

HDU 5795 A Simple Nim (SG博弈)

A Simple Nim

Problem Description

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 interesting,players can separate one heap into three smaller heaps(no empty heaps)instead of the picking operation.Please find out which player will win the game if each of them never make mistakes.

Input

Intput contains multiple test cases. The first line is an integer1≤T≤100, the number of test cases. Each case begins with an integer n, indicating the number of the heaps, the next line contains N integerss[0],s[1],....,s[n−1], representing heaps with s[0],s[1],...,s[n−1] objects respectively.(1≤n≤106,1≤s[i]≤109)

Output

For each test case,output a line whick contains either"First player wins."or"Second player wins".

Sample Input

2 2 4 4 3 1 2 4

Sample Output

Second player wins. First player wins.

Author

UESTC

Source

​​2016 Multi-University Training Contest 6​​

Recommend

wange2014   |   We have carefully selected several similar problems for you:  ​​5803​​​ ​​5802​​​ ​​5801​​​ ​​5800​​​ ​​5799​​

题意:有 n堆的取石子游戏,规定每次可以取一堆中的任意个,或者将当前堆分为三个非空堆。最后一个取石子的胜。求先手胜还是后手必胜。

题解: 打表找规律。

sg[0]=0;

当k%8==7时sg[x]=k+1,

当k%8==0时sg[x]=k-1 ,

其余时候:sg[x]=x;(k>=0)

打表代码:

#includeint g[100];int f[100];void Da_Biao(int n){ memset(f,false,sizeof(f)); for(int i=0;i

AC代码:

#includeusing namespace std;int SG(int x){ if(x%8==0)return x-1; if(x%8==7)return x+1; return x;}int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int ans=0; int a=0; for(int i=0;i

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:2021年饮品行业营销里,今麦郎出圈的创意公式是什么?
下一篇:HDU 5776 BestCoder Round #85 sum (数学)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~