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

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
 
Source
 
Recommend
gaojie   |   We have carefully selected several similar
problems for you:  3031 3033 3038 3035 3034 
 
 
Multi-SG游戏的裸题
$$sg(x) = \begin{cases} x-1, & \text{$x\%4=0$}\\ x, & \text{$x\%4=1\lor x\%4=2$ }\\ x+1, & \text{$x\%4=3$} \end{cases}$$
 
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=;
int read()
{
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int a[MAXN],SG[MAXN];
int main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#else
#endif
int QWQ=read();
while(QWQ--)
{
int N=read();
for(int i=;i<=N;i++) a[i]=read();
for(int i=;i<=N;i++)
if(a[i] % == ) SG[i] = a[i]-;
else if(a[i]%==||a[i]%==) SG[i] = a[i];
else SG[i] = a[i]+;
int ans=;
for(int i=;i<=N;i++)
ans^=SG[i];
puts(ans?"Alice":"Bob");
}
return ;
}
 

HDU 3032 Nim or not Nim?(Multi-Nim)的更多相关文章

  1. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  2. hdu 3032 Nim or not Nim? sg函数 难度:0

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. HDU 3032 multi-sg 打表找规律

    普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...

  4. 【hdu 3032】Nim or not Nim?

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

  5. HDU 3032 Nim or not Nim (sg函数)

    加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...

  6. HDU 3032 (Nim博弈变形) Nim or not Nim?

    博弈的题目,打表找规律还是相当有用的一个技巧. 这个游戏在原始的Nim游戏基础上又新加了一个操作,就是游戏者可以将一堆分成两堆. 这个SG函数值是多少并不明显,还是用记忆化搜索的方式打个表,规律就相当 ...

  7. hdu 3032 Nim or not Nim? 博弈论

     这题是Lasker’s Nim. Clearly the Sprague-Grundy function for the one-pile game satisfies g(0) = 0 and g( ...

  8. HDU 3032 Nim or not Nim? (sg函数求解)

    Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which players ...

  9. HDU 3032 Nim or not Nim? (需求的游戏SG功能)

    意甲冠军:经典Nim游戏转换,给你n礧pi,每个堆栈有pi石头, Alice和Bob轮流石头,意一堆中拿走随意个石子,也能够将某一堆石子分成两个小堆 (每堆石子个数必须不能为0).先拿完者获胜 思路: ...

  10. HDU 3032 Nim or not Nim? [Multi-SG]

    传送门 题意: nim游戏,多了一种操作:将一堆分成两堆 Multi-SG游戏规定,在符合拓扑原则的前提下,一个单一游戏的后继可以为多个单一游戏. 仍然可以使用$SG$函数,分成多个游戏的后继$SG$ ...

随机推荐

  1. IntelliJ IDEA 常用快捷键使用说明

    Ctrl + / 可以实现单行注释的快速添加和取消.xml和html注释也能操作. Ctrl + Y 删除选中的代码,或者光标所在行,同时删除代码所占的空间. Ctrl + Alt + V 快速抽取变 ...

  2. 哦,这就是java的优雅停机?(实现及原理)

    优雅停机? 这个名词我是服的,如果抛开专业不谈,多好的名词啊! 其实优雅停机,就是在要关闭服务之前,不是立马全部关停,而是做好一些善后操作,比如:关闭线程.释放连接资源等. 再比如,就是不会让调用方的 ...

  3. 使用ajax的post方式下载excel

    项目需求,前端发起ajax请求,后端生成excel并下载,同时需要在header头中,带上token验证信息,参考了很多文章,最终实现如下: PHP后端使用base64: $filename = 'd ...

  4. websocket ----简介,以及demo

    #导报 from dwebsocket.decorators import accept_websocket WebSocket是一种在单个TCP连接上进行全双工通信的协议 WebSocket使得客户 ...

  5. 剑指offer【07】- 斐波那契数列(java)

    题目:斐波那契数列 考点:递归和循环 题目描述:大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0),n<=39. 法一:递归法,不过递归比较慢, ...

  6. 使用ANNdotNET进行情感分析

    2018年10月的MSDN杂志上发表了由James McCaffrey撰写的文章“使用CNTK的情感分析” .在这篇博文中,我将向您介绍这篇非常好且写得很好的MSDN文章示例.我不打算重复MSDN文章 ...

  7. Windows2008/2012/2016多用户同时远程连接终端服务授权

    win2016多用户登录: 添加角色“远程桌面服务”,子角色“远程桌面会话主机”和“远程桌面授权”,重启 远程桌面授权,激活服务器,企业协议,协议号6565792,授权模式“每用户” 本地策略管理器g ...

  8. 【干货】利用MVC5+EF6搭建博客系统(一)EF Code frist、实现泛型数据仓储以及业务逻辑

    习MVC有一段时间了,决定自己写一套Demo了,写完源码再共享. PS:如果图片模糊,鼠标右击复制图片网址,然后在浏览器中打开即可. 一.框架搭建 二.创建数据库 1.创建一个空的EF code fr ...

  9. 10 Tensorflow模型保存与读取

    我们的模型训练出来想给别人用,或者是我今天训练不完,明天想接着训练,怎么办?这就需要模型的保存与读取.看代码: import tensorflow as tf import numpy as np i ...

  10. crontab的使用笔记

    1 crond简介crond是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动cron ...