HDU 3032 Nim or not Nim?(Multi-Nim)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2508 Accepted Submission(s):
1297
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.
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)
"Alice" or "Bob", which is the winner of this game. Alice will play first. You
may asume they never make mistakes.
3
2 2 3
2
3 3
Bob
#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)的更多相关文章
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- 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 ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
- 【hdu 3032】Nim or not Nim?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...
- HDU 3032 Nim or not Nim (sg函数)
加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...
- HDU 3032 (Nim博弈变形) Nim or not Nim?
博弈的题目,打表找规律还是相当有用的一个技巧. 这个游戏在原始的Nim游戏基础上又新加了一个操作,就是游戏者可以将一堆分成两堆. 这个SG函数值是多少并不明显,还是用记忆化搜索的方式打个表,规律就相当 ...
- 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( ...
- 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 ...
- HDU 3032 Nim or not Nim? (需求的游戏SG功能)
意甲冠军:经典Nim游戏转换,给你n礧pi,每个堆栈有pi石头, Alice和Bob轮流石头,意一堆中拿走随意个石子,也能够将某一堆石子分成两个小堆 (每堆石子个数必须不能为0).先拿完者获胜 思路: ...
- HDU 3032 Nim or not Nim? [Multi-SG]
传送门 题意: nim游戏,多了一种操作:将一堆分成两堆 Multi-SG游戏规定,在符合拓扑原则的前提下,一个单一游戏的后继可以为多个单一游戏. 仍然可以使用$SG$函数,分成多个游戏的后继$SG$ ...
随机推荐
- 第69节:Java中数据库的多表操作
第69节:Java中数据库的多表操作 前言 学习数据库的多表操作,去电商行业做项目吧!!! 达叔,理工男,简书作者&全栈工程师,感性理性兼备的写作者,个人独立开发者,我相信你也可以!阅读他的文 ...
- 原生JS-旋转木马
原生JS-旋转木马 今天写一个原生JS写的旋转木马JS效果. 实现原理: 1.建立一个数组给每一张图片写对应的z-index,opacity,top,width: 2.实现旋转的操作是把建造的数组里面 ...
- JavaScript 对象(下)
getter 和 setter: 1.ES5 里,属性值可以用一个或两个方法代替,这两个方法就是 getter 和 setter,它们使用 get 和 set 进行定义而不是通过 function 2 ...
- JavaScript深入(操作BOM对象)
浏览器对象模型(BOM) BOM的核心是window, 向下有: document(文档):document下由button,text,from,等等表单元素组成. location(地址对象),hi ...
- Scala - 快速学习04 - 求值策略
表达式求值策略(Evaluation Strategy) Scala中所有的运算都是基于表达式的. Call By Value - 对函数实参求值,且仅求值一次:函数调用之前对所有表达式进行求值 Ca ...
- pycharm安装plugins
1 . 启动 PyCharm 软件 2 . 打开 设置(Setting) 窗口.(操作:File -> Setting 或者 按快捷键 Ctrl + Alt + S) 3 . 在搜索框里面搜索: ...
- Spring概况(一)
spring是什么? spring是一个开源框架,最初是为了解决企业应用开发的复杂性而创建的,但现在已经不止应用于企业应用. 是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架. - 从大 ...
- DotNetCore深入了解之一Startup类
一个典型的ASP.NET Core应用程序会包含Program与Startup两个文件.Program类中有应用程序的入口方法Main,其中的处理逻辑通常是创建一个WebHostBuilder,再生成 ...
- [java]创建一个默认TreeMap() key为什么不能为null
本文版权归 远方的风lyh和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 先看一下 TreeMap 的 put(K key, V value) public TreeMap() ...
- 面试必备技能-HiveSQL优化
Hive SQL基本上适用大数据领域离线数据处理的大部分场景.Hive SQL的优化也是我们必须掌握的技能,而且,面试一定会问.那么,我希望面试者能答出其中的80%优化点,在这个问题上才算过关. Hi ...