Nim or not Nim?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1056    Accepted Submission(s): 523

Problem Description
Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap.

Nim is usually played as a misere game, in which the player to take the last object loses. Nim can also be played as a normal play game, which means that the person who makes the last move (i.e., who takes the last object) wins. This is called normal play because most games follow this convention, even though Nim usually does not.

Alice and Bob is tired of playing Nim under the standard rule, so they make a difference by also allowing the player to separate one of the heaps into two smaller ones. That is, each turn the player may either remove any number of objects from a heap or separate a heap into two smaller ones, and the one who takes the last object wins.

 
Input
Input contains multiple test cases. The first line is an integer 1 ≤ 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 integers s[0], s[1], ...., s[N-1], representing heaps with s[0], s[1], ..., s[N-1] objects respectively.(1 ≤ N ≤ 10^6, 1 ≤ S[i] ≤ 2^31 - 1)
 
Output
For each test case, output a line which contains either "Alice" or "Bob", which is the winner of this game. Alice will play first. You may asume they never make mistakes.
 
Sample Input
2
3
2 2 3
2
3 3
 
Sample Output
Alice Bob

sg函数打表找规律即可

//hdu 3032
//任意分堆 注意 sg函数具体意义
#include <stdio.h> int main()
{
int T;
scanf("%d", &T);
while(T --)
{
int n, ans = 0, m;
scanf("%d", &n);
while(n --)
{
scanf("%d", &m);
if(m % 4 == 0) ans ^= (m - 1);
else if(m % 4 == 3) ans ^= (m + 1);
else ans ^= m;
}
if(ans == 0) puts("Bob");
else puts("Alice");
}
return 0;
}

  

hdu 3032 Nim or not Nim? sg函数 难度:0的更多相关文章

  1. hdu 1079 Calendar Game sg函数 难度:0

    Calendar Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. hdu 1536&&1944 S-Nim sg函数 难度:0

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. hdu 1517 A Multiplication Game 段sg 博弈 难度:0

    A Multiplication Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  4. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  5. HDU 1848 Fibonacci again and again(SG函数)

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  6. hdu 4559 涂色游戏(对SG函数的深入理解,推导打SG表)

    提议分析: 1 <= N <= 4747 很明显应该不会有规律的,打表发现真没有 按题意应该分成两种情况考虑,然后求其异或(SG函数性质) (1)找出单独的一个(一列中只有一个) (2)找 ...

  7. hdu 3980 Paint Chain 组合游戏 SG函数

    题目链接 题意 有一个\(n\)个珠子的环,两人轮流给环上的珠子涂色.规定每次涂色必须涂连续的\(m\)颗珠子,无法继续操作的人输.问先手能否赢. 思路 参考 转化 第一个人取完之后就变成了一条链,现 ...

  8. HDU 1848 Fibonacci again and again SG函数做博弈

    传送门 题意: 有三堆石子,双方轮流从某堆石子中去f个石子,直到不能取,问先手是否必胜,其中f为斐波那契数. 思路: 利用SG函数求解即可. /* * @Author: chenkexing * @D ...

  9. HDU 1524 A Chess Game【SG函数】

    题意:一个N个点的拓扑图,有M个棋子,两个人轮流操作,每次操作可以把一个点的棋子移动到它的一个后继点上(每个点可以放多个棋子),直到不能操作,问先手是否赢. 思路:DFS求每个点的SG值,没有后继的点 ...

随机推荐

  1. URAL - 1091 Tmutarakan Exams (简单容斥原理)

    题意:K个不同数组成的集合,每个数都不超过S且它们的gcd>1.求这样的数的个数 分析:从2开始枚举gcd,但这样会发生重复.譬如,枚举gcd=2的集合个数和gcd=3的集合个数,枚举6的时候就 ...

  2. git 移除某个文件的版本管理

    1:最简单的,在项目刚创建的时候,在根目录的.gitignore,加入该文件的相对路径 2:已经被纳入到了版本控制,使用在当前目录下,打开cmd窗口 输入rm命令,加上文件的绝对路径(相对路径没试过) ...

  3. NOIP2019前的训练记录

    \(April\):肛多项式,学\(FWT\)一个小时无果后背了六个公式,看来证明又得咕很久了

  4. awk二十问-【AWK学习之旅】

    ---===AWK学习之旅===--- 一行命令: 1.打印输入每行的字段总数: 最后一行的字段总数:END{print NF} 每行都显示字段总数: {print NF}   2.打印指定行: aw ...

  5. 20145310 《Java程序设计》第5周学习总结

    20145310 <Java程序设计>第5周学习总结 教材学习内容总结 本周主要进行第八章和第九章的学习. java中所有的错误都会打包为对象,可以try catch代表错误的对象后做一些 ...

  6. 20135302魏静静——linux课程第八周实验及总结

    linux课程第八周实验及总结 实验及学习总结 1. 进程切换在内核中的实现 linux中进程切换是很常见的一个操作,而这个操作是在内核中实现的. 实现的时机有以下三个时机: 中断处理过程(包括时钟中 ...

  7. [翻译]CSS模块-未来的编码方式

    前言 这是Glen Maddern发布于2015年8月19日的一篇文章,主要是之前翻译的文章<理解CSS模块方法>里提到这篇文章,现在算是顺藤摸瓜跟进来看看. 这里的翻译都是根据我自己的理 ...

  8. The Startup Manager FAQ

    Main Features: 1.  Login Items: Manageable list of applications that are launched automatically ever ...

  9. PHP中的_FILE_和_DIR_的区别

    <?php$dir = dirname(__FILE__);?>在PHP5.3中,增加了一个新的常量__DIR__,指向当前执行的PHP脚本所在的目录.例如当前执行的PHP文件为 /www ...

  10. rhel7配置链路聚合(双网卡热备)

    team方法 1). nmcli connection add type team con-name team0 ifname team0 config '{"runer":{&q ...