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 ...
随机推荐
- eclipse平台
eclipse 是一个平台!!!! 能连ssh,能连db,能连windows Eclipse http://www.eclipse.org/downloads/packages/release/Neo ...
- numpy.distutils.system_info.NotFoundError: no lapack/blas resources found
python35用pip安装scipy的时候报错 numpy.distutils.system_info.NotFoundError: no lapack/blas resources found 原 ...
- arcgis 10.1 错误(TCP_NODELAY NOT enabled)
Procedure The steps provided require that you briefly stop the license manager. During this time, co ...
- VSFTP服务器
vsftpd 是"very secure FTP daemon"的缩写,安全性是它的一个最大的特点.vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 ...
- VS问题:该依赖项是由项目系统添加的,不能删除。
该依赖项是由项目系统添加的,不能删除. 原因:是该项目添加对依赖项的引用时,不是直接引用的dll,而是通过“添加引用->项目”的方式引用的项目. 解决:删除“引用”目录下该依赖项的引用,然后通过 ...
- mpstat, pidstat, iostat和sar
在我们上一篇文章中,我们已经学习了如何去安装和更新sysstat,并且了解了包中的一些实用工具. 今天,我们将会通过一些有趣的实例来学习mpstat, pidstat, iostat和sar等工具,这 ...
- python--ulipad控制台中文输出乱码
ulipad用起来顺手,而不尽人意的地方时,它不能正确输出中文.而且有人指出这和文件的编码没关系,所以将”设置“选项里”缺省文档编码“修改为”utf-8“也无济于事.为了解决这个问题,我在网上搜了搜, ...
- Hibernate工作原理
现在我们知道了一个概念Hibernate Session,只有处于Session管理下的POJO才具有持久化操作能力.当应用程序对于处于Session管理下的POJO实例执行操作时,Hibernate ...
- java byte转无符号int
import java.io.ByteArrayInputStream; public class Test{ public static void main(String[] args) { byt ...
- [ActionScritp 3.0] 使用LocalConnection建立通信
包 flash.net 类 public class LocalConnection 继承 LocalConnection → EventDispatcher → Object 语言版本: Acti ...