HDU 4994 博弈。
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
---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
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
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 博弈。的更多相关文章
- Revenge of Nim hdu 4994 (博弈)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4994 题意:现在有两个人在取石子,共有n堆石子,每堆石子取完后才可以取下一堆石子,最后一个取石子的人 ...
- hdu 4994(博弈)
Revenge of Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- HDU - 4994 Revenge of Nim (取石子游戏)
Problem Description Nim is a mathematical game of strategy in which two players take turns removing ...
- hdu 4994 前后有序Nim游戏
http://acm.hdu.edu.cn/showproblem.php?pid=4994 Nim游戏变成从前往后有序的,谁是winner? 如果当前堆数目为1,玩家没有选择,只能取走.遇到到不为1 ...
- BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 题目意思:有 n 个 heap(假设从左至右编号为1-n),每个 heap 上有一些 objec ...
- HDU 5996 博弈
http://acm.hdu.edu.cn/showproblem.php?pid=5996 博弈论待补. 这题变化了一下,因为注意到奇数层的东西(层数从1开始),对手可以模仿地动,那就相当于没动. ...
- A - 无聊的游戏 HDU - 1525(博弈)
A - 无聊的游戏 HDU - 1525 疫情当下,有两个很无聊的人,小A和小B,准备玩一个游戏,玩法是这样的,从两个自然数开始比赛.第一个玩家小A从两个数字中的较大者减去两个数字中较小者的任何正倍数 ...
- hdu 1517 博弈 **
博弈题: 题意:2 个人玩游戏,从 1 开始,轮流对数进行累乘,直到超过一个指定的值. 解题思路:如果输入是 2 ~ 9 ,因为Stan 是先手,所以Stan 必胜如果输入是 10~18 ,因为Oll ...
随机推荐
- kubernetes concepts -- Pod Lifecycle
Pod Lifecycle This page describes the lifecycle of a Pod. Pod phase A Pod’s status field is a PodSta ...
- 关于SOA架构设计的案例分析
关于SOA架构设计的案例分析 面向服务的体系结构(SOA)是一个组件模型,它将应用程序的不同功能单元(称为服务)通过这些服务之间定义良好的接口和契约联系起来.它可以根据需求通过网络对松散耦合的粗粒度应 ...
- 【中文乱码】深入分析 Java Web 中的中文编码问题
深入分析 Java Web 中的中文编码问题 1.几种常见的编码格式 1.1 为什么要编码 在计算机中存储信息的最小单元是 1 个字节,即 8 个 bit, 所以能表示的字符范围是 0 ~ 255 个 ...
- ERR : undefined reference to something
序言: define : 定义.相信你用过 #define PI 3.141592653 (千万记得别在这句代码后加分号) reference : 引用 undefined reference to ...
- pyautogui介绍
https://pyautogui.readthedocs.io/en/latest/introduction.html Introduction Purpose The purpose of PyA ...
- Ubuntu学习之路2
由于数据越来越多,学习的也稍微多了点,故将一步一步学习到的命令和快捷键继续到这篇博客. 1. 查看隐藏文件和文件夹 Ctrl+H 2. 打开搜索管理器 Alt+F2 3. 查看系统内存 free -h ...
- SpringBoot配置嵌入式Servlet容器
1).如何定制和修改Servlet容器的相关配置: 1.修改和server有关的配置(ServerProperties[也是EmbeddedServletContainerCustomizer]): ...
- Day7-Python3基础-面向对象进阶
内容: 面向对象高级语法部分异常处理 经典类vs新式类 静态方法.类方法.属性方法 类的特殊方法 反射 Socket开发基础 面向对象高级语法部分 静态方法 通过@staticmethod ...
- 工具之sort
转自:http://www.cnblogs.com/dong008259/archive/2011/12/08/2281214.html sort命令是帮我们依据不同的数据类型进行排序,其语法及常用参 ...
- Dubbo如何支持本地调用?injvm方式解析
Dubbo是一个远程调用的框架,对于一个服务提供者,暴露了一个接口供外部消费者调用,那么对于提供者自己是否可以调用这个接口,需要什么特殊处理吗? 这篇文章就分享下Dubbo关于本地调用的实现机制,以及 ...