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 ...
随机推荐
- async-await 线程分析
这里没有线程 原文地址:https://blog.stephencleary.com/2013/11/there-is-no-thread.html 前言 我是在看 C#8.0 新特性异步流时在评论里 ...
- 19秦皇岛现场赛F题 dfs
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6736 如果环的边长为k,那么环的删边方案数是2k-1.如果链的边长为k,那么链的删边方案数是2k.环的 ...
- Django redis 应用
一.自定义连接池 与python中使用连接池一样(使用单例对象) 注意:每个视图函数都要有 conn = redis.Redis(connection_pool=POOL) 二.使用第三方模块(dja ...
- 查看jvm内存信息
Runtime.getRuntime().maxMemory(); //最大可用内存,对应-Xmx Runtime.getRuntime().freeMemory(); //当前JVM空闲内存 Run ...
- 6、python基本数据类型之序列类型
前言:python的基本数据类型可以分为三类:数值类型.序列类型.散列类型,本文主要介绍序列类型及其通用操作. 一.序列类型 1)字符串(str):用单引号('),双引号("),三引号(三单 ...
- 玩转Django2.0---Django笔记建站基础七(表单与模型)
第七章 表单与模型 表单是搜集用户数据信息的各种表单元素的集合,作用是实现网页上的数据交互,用户在网站输入信息,然后提交到网站服务器端进行处理(如数据录入和用户登录.注册等). 用户表单是web开发的 ...
- xlwings excel(四)
前言 当年看<别怕,Excel VBA其实很简单>相见恨晚,看了第一版电子版之后,买了纸质版,然后将其送人.而后,发现出了第二版,买之收藏.之后,发现Python这一编程语言,简直是逆天, ...
- Python中类属性和实例属性的区别
在Python中经常会混淆类属性和实例属性的概念,今天专门记录一下个人理解以免日后忘记. 看下面的例子: class Tencent(): i = 10 # 此处i为类属性 def __init__( ...
- python之set集合操作
set集合天生具有去重功能 1.创建集合,集合的value类型:string.tuple.frozenset.数字等不可变类型: s1 =set()#空集合 s2=set(") s3=set ...
- springboot中的那些连接池
hello~各位读者新年好! 回想起前几天在部署springboot项目到正线时,线上环境要求jdk7,可项目是基于jdk8开发的,springboot也是用的springboot2以上的版本,可以说 ...