F - 6

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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 思路: 博弈, 先找必胜状态或必败状态, 判断控制权在谁手里,他就必胜, 判断控制权在谁手里就判断第一个非1的数钱有几个1 如果是偶数个控制权就在第一个手里。 代码:
#include<stdio.h>
#include<string.h> #define N 110000
int main(void)
{
int t, i, j, n, f, ok;
int a[N];
scanf("%d", &t); while(t--)
{
f = ;
ok = ; scanf("%d", &n); for(i = ; i < n; i++)
scanf("%d", &a[i]); for(i = ; i < n; i++)
{
if(a[i] > )
{
ok = ;//判断是否全是1.
break;
} else
f++;//判断第一个不是1的位置。
} if(ok==)//如果有非1的存在,就判断控制权再谁手里, 如果在第一非1的数前有偶数个1控制权在第一个人手里。
{
if(f%)
printf("No\n");
else
printf("Yes\n");
}
else//如果全是1的话,如果有奇数堆第一个人必胜。
{
if(f%)
printf("Yes\n");
else
printf("No\n");
} }
return ; }

HDU 4994 博弈。的更多相关文章

  1. Revenge of Nim hdu 4994 (博弈)

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

  2. hdu 4994(博弈)

    Revenge of Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  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. dubbo配置文件解读(2)

    <dubbo:service/> <dubbo:reference/> <dubbo:protocol/> <dubbo:registry/> < ...

  2. SpringSecurity 自定义表单登录

    SpringSecurity 自定义表单登录 本篇主要讲解 在SpringSecurity中 如何 自定义表单登录 , SpringSecurity默认提供了一个表单登录,但是实际项目里肯定无法使用的 ...

  3. Entity Framework 6+ 连接Mysql

    好吧.这个博客开不开的 我感觉.. 都一样了. 前言: 公司改造Sqlserver ->Mysql Sql2016老夫对不住你啊.. 好 前沿结束. 需要的家伙: 1.mysql-for-vis ...

  4. 关于C++读入数字按位取出与进制转换问题

    这一片博客我就不写具体的一个题了,只是总结一种典型问题——读入数字按位取出. 就拿数字12345举例吧. 是首先,我们要取出个位.这样取出: 12345/1=12345 12345%10=5.    ...

  5. 团队项目-Beta冲刺(第一周)

    团队项目-Beta冲刺(第一周) 一. 作业描述 这个作业属于哪个课程 这个作业要求在哪里 团队名称 CTRL-IKun 这个作业的目标 合理安排时间完成接下来的任务,剩余任务预估,分配任务(开发,测 ...

  6. 01-前言&WEB标准

    人生苦短,要学就只学有用的 [前端教学-前言] 初识web开发 我们先来认识一下web前端 其实前端的工作,大体的概括就是:根据美工给的设计稿,变成web网页,使用后天的接口实现数据的渲染,要是高端一 ...

  7. openlayer3 坐标系转换

    'EPSG:4326'-经纬度坐标-WGS84'EPSG:3857'- xy坐标-web墨卡托 ol3默认的坐标系为3857,即在创建ol.map的时候,若不指定projection,则默认为EPSG ...

  8. Activity工作流框架入门(二)API使用DEMO

    工作流API使用Demo package activity.demo.test; import java.io.File; import java.io.FileInputStream; import ...

  9. Centos 7x 安装 Telegram MTproxy代理【完美可用】

    0x00 最近迷上了Telegram,也就是电报,觉得通过这个获取国外的新闻比较方便 可是我的VPS小机子不给力,一开始使用的Centos 6x,死活装不上去, 发现MTproxy不支持Centos ...

  10. iNeuOS工业互联平台,iNeuKernel(物联网核心组件)远程控制标准化设计与实现。发布v2.3版本。

    目       录 1.      概述... 2 2.      平台演示... 2 3.      控制端与iNeuKernel的交互协议... 3 4.      设备驱动实现控制业务... 4 ...