c语言sscanf函数的用法是什么
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)
打表代码:
#include AC代码: #include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~