Revenge of Nim

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

Problem Description
Nim
is a mathematical game of strategy in which two 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.
---Wikipedia

Today, Nim takes
revenge on you. The rule of the game has changed a little: the player
must remove the objects from the current head(first) heap. Only the
current head heap is empty can the player start to remove from the new
head heap. As usual, the player who takes the last object wins.

 
Input
The first line contains a single integer T, indicating the number of test cases.

Each
test case begins with an integer N, indicating the number of heaps.
Then N integer Ai follows, indicating the number of each heap
successively, and the player must take objects in this order, from the
first to the last.

[Technical Specification]
1. 1 <= T <= 100
2. 1 <= N <= 1 000
3. 1 <= Ai <= 1 000 000 000

 
Output
For each test case, output “Yes” if the first player can always win, otherwise “No”.
 
Sample Input
2
1
2
2
1 1
 
Sample Output
Yes
No
 
Source
 
题意:按照顺序取完n堆石子,每次取一个或者一堆。
关键点:看出取到第一个>1的石子堆的人是必胜态。
/**
对于某个人来说,只要他能够取到第一个>1的堆,那么他就可以决定后面的人的状态了,所以第一个取到>1的堆的人
是赢家。所以我们只要讨论前面有多少==1的堆就行了。
2.如果里面存在>1的堆,那么在第一个>1的堆前面有偶数个=1的堆先手才会赢
1.如果没有>1的堆,那么奇数个=1的堆先手就会赢。
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long LL; int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
int n,cnt=,v;
bool flag = false;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&v);
if(v>&&!flag)
{
flag = true;
cnt = i-;
}
}
if(!flag) cnt = n;
if(flag){
if(cnt%==) printf("No\n");
else printf("Yes\n");
}else{
if(cnt%==) printf("No\n");
else printf("Yes\n");
}
}
return ;
}

hdu 4994(博弈)的更多相关文章

  1. HDU 4994 博弈。

    F - 6 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  2. Revenge of Nim hdu 4994 (博弈)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4994 题意:现在有两个人在取石子,共有n堆石子,每堆石子取完后才可以取下一堆石子,最后一个取石子的人 ...

  3. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  4. HDU - 4994 Revenge of Nim (取石子游戏)

    Problem Description Nim is a mathematical game of strategy in which two players take turns removing ...

  5. hdu 4994 前后有序Nim游戏

    http://acm.hdu.edu.cn/showproblem.php?pid=4994 Nim游戏变成从前往后有序的,谁是winner? 如果当前堆数目为1,玩家没有选择,只能取走.遇到到不为1 ...

  6. BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 题目意思:有 n 个 heap(假设从左至右编号为1-n),每个 heap 上有一些 objec ...

  7. HDU 5996 博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=5996 博弈论待补. 这题变化了一下,因为注意到奇数层的东西(层数从1开始),对手可以模仿地动,那就相当于没动. ...

  8. A - 无聊的游戏 HDU - 1525(博弈)

    A - 无聊的游戏 HDU - 1525 疫情当下,有两个很无聊的人,小A和小B,准备玩一个游戏,玩法是这样的,从两个自然数开始比赛.第一个玩家小A从两个数字中的较大者减去两个数字中较小者的任何正倍数 ...

  9. hdu 1517 博弈 **

    博弈题: 题意:2 个人玩游戏,从 1 开始,轮流对数进行累乘,直到超过一个指定的值. 解题思路:如果输入是 2 ~ 9 ,因为Stan 是先手,所以Stan 必胜如果输入是 10~18 ,因为Oll ...

随机推荐

  1. Python9-From-CSS-day48

    1.form表单相关内容前后端有数据交互的时候用form表单form表单提交数据的几个注意事项: 1.所有获取用户输入的标签都必须放在form表单里面 2.action 控制着往哪里提交 3.inpu ...

  2. 华东交通大学2018年ACM“双基”程序设计竞赛 K

    MIKU酱是个玩游戏氪金的人,游戏公司给她制定了新的规则,如果想从关卡i到关卡j,你需要交一些钱就可以了,但同时,MIKU酱的爸爸zjw很爱她,所以她可以每过一关就向她爸要一次钱,但她爸每次给他的钱是 ...

  3. Hi3518EV300编译U-Boot和内核报错:loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed. Aborted (core dumped)

    下载Hi3518EV300的SDK后编译内核和U-boot,发现爆出如下错误: scripts/kconfig/conf --silentoldconfig Kconfig Aborted (core ...

  4. hdu 1257最少拦截系统

    最少拦截系统 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的 ...

  5. 教你如何在 Javascript 文件里使用 .Net MVC Razor 语法

    摘录 文章主要是介绍了通过一个第三方类库RazorJS,实现Javascript 文件里使用 .Net MVC Razor 语法,很巧妙,推荐给大家 相信大家都试过在一个 View 里嵌套使用 jav ...

  6. [转]using components in Cakephp 2+ Shell

    <?php App::uses('AppShell', 'Console/Command'); App::uses('ComponentCollection', 'Controller'); A ...

  7. CMD命令简介

    cmd是command的缩写.即命令行 . 虽然随着计算机产业的发展,Windows 操作系统的应用越来越广泛,DOS 面临着被淘汰的命运,但是因为它运行安全.稳定,有的用户还在使用,所以一般Wind ...

  8. 五分钟搞定Linux容器

    [TechTarget中国原创] Linux容器针对特定工作负载提供了全新的灵活性与可能性.存在很多解决方案,但是没有一个解决方案能够像systemd容器那样进行快速部署.给我五分钟,本文将介绍如何使 ...

  9. 项目管理者必知:适用于仪表盘项目的7个优秀JavaScript库

    仪表盘是用于目标或业务流程的视觉指示工具,也用于切割杂乱无章的数据,从而分割出要点的重要工具.它可以帮助评估信息并及时做出正确的决定,一款实时可视化的仪表盘通常由图标.测绘图.图形符号以及数据表格等组 ...

  10. 使用shell脚本生成数据库markdown文档

    学习shell脚本编程的一次实践,通过shell脚本生成数据库的markdown文档,代码如下: HOST=xxxxxx PORT=xxxx USER="xxxxx" PASSWO ...