Revenge of Nim hdu 4994 (博弈)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4994
题意:现在有两个人在取石子,共有n堆石子,每堆石子取完后才可以取下一堆石子,最后一个取石子的人胜利输出'Yes',否则输出'No'
分析:要想看最后一堆石子是谁取走的,我们则需要判断在前n-1堆石子中,主动权在谁的手上。试想,除了在迫不得已的情况下(a[i]==1)不得不这么取,两个人都可以通过取(1-a[i])不等的石子来确保自己手里的主动权。倘若在遇到比1大的数字时,只需要判断在这个数字前面有几个1,继而来判断现在主动权在谁的手上。
若有(ans%2==0)个1,则肯定是第一个人取得胜利,反之第二个人。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h> using namespace std; #define INF 0x3f3f3f3f
const int maxn = ;
typedef long long LL;
int a[maxn]; int main()
{
int T, n; scanf("%d", &T); while(T --)
{
scanf("%d", &n); memset(a, , sizeof(a));
for(int i=; i<=n; i++)
scanf("%d", &a[i]); if(n==) printf("Yes\n");
else
{
int ans = ; for(int i=; i<n; i++)
{
if(a[i]>) break;
ans ++;
} if(ans % == )
printf("Yes\n");
else
printf("No\n"); } }
return ;
}
Revenge of Nim hdu 4994 (博弈)的更多相关文章
- BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994 题目意思:有 n 个 heap(假设从左至右编号为1-n),每个 heap 上有一些 objec ...
- HDU 4994 博弈。
F - 6 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- hdu 4994(博弈)
Revenge of Nim Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU5088——Revenge of Nim II(高斯消元&矩阵的秩)(BestCoder Round #16)
Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players tak ...
- HDOJ 5088 Revenge of Nim II 位运算
位运算.. .. Revenge of Nim II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 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 ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
随机推荐
- jquery选择器之属性选择器
[attribute] 匹配指定属性名的所有元素 [attribute=value] 匹配给定的属性名是某个特定值的属性 [attribute!=value] 匹配给定的属性名不是某个特定值的属性 ...
- Windows 2003上 SaltStack/Salt 和 psutil 可能存在的问题及解决
今天把salt安装在windows 2003上,发现无法启动,随之而来的是一个有一个的坑,让我们一起逐个排查. 问题一(salt无法启动) salt无法启动,错误结果如图:
- Cannot find executable for CFBundle 解决办法
出错日志为:2013-12-29 01:17:49.785 Displaying Alerts with UIAlertView[419:70b] Cannot find executable for ...
- 最小的K个数:用快排的思想去解相关问题
实现快速排序算法的关键在于先在数组中选择一个数字,接下来把数组中的数字分为两部分,比选择的数字小的数字移到数组的左边,比选择的数字大的数字移到数组的右边. 这个函数可以如下实现: int Partit ...
- SQL%NOTFOUND
异常相关: 源地址:https://zhidao.baidu.com/question/215737667.html EXCEPTIONwhen others thenrollback;dbms_ou ...
- 1.date 命令
转自:http://www.cnblogs.com/peida/archive/2012/12/13/2815687.html 在linux环境中,不管是编程还是其他维护,时间是必不可少的,也经常会用 ...
- (整理)PowerDesign与EF的文档说明
最近通过PowerDesign->SQLServer->VS的方式,将数据库设计.创建.实体模型生成等环节打通,发现VS中的Model竟然没有说明,然后就在园子里找了一下,发现了园友的文章 ...
- ForeignKey 的第二个位置参数on_delete
on_delete指的是通过ForeignKey连接起来的对象被删除后,当前字段怎么变化. 常见的选项有: models.CASCADE,对就对象删除后,包含ForeignKey的字段也会被删除 mo ...
- linux下查找某个文件位置的方法
一.通过文件名查找法: 举例说明,假设你忘记了httpd.conf这个文件在系统的哪个目录 下,甚至在系统的某个地方也不知道,则这是可以使用如下命令: find / -name httpd.conf ...
- dijkstra
寻找从源结点到其他点之间的最短距离. 把给出的结点分成两组,一组a刚开始为空,另一组b为全部节点,dis[i]记录从源点到i结点的距离,同样当所有操作结束后dis[i]就是到达源点的最短距离啦,每次更 ...