POJ1704 Georgia and Bob Nim游戏
这道题可以转化为经典的Nim游戏来解决。
Nim游戏是这样的
有n堆石子,每堆各有ai个。 两个人轮流在任意石子堆中取至少1个石子,不能再取的输。
解决方法如下, 对N堆石子求异或 为0则甲必胜 否则乙必胜 证明略。
对于这道题目 两个棋子的间距可以当作Nim石子的一堆来处理,
当然,在这个题目中 玩家把左边的棋子向左移动后等于给Nim石堆增加了石子,不过无伤大雅。只要减去对应的石子数就回到了原状态
代码很简单 输入数据是无序的 需要排序
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=1001;
int N,P[MAXN]; void solve()
{
if(N%2==1){P[N++]=0;sort(P,P+N);} int x=0;
for(int i=0;i+1<N;i+=2)
x^=(P[i+1]-P[i]-1);
if(x==0)printf("Bob will win\n");
else printf("Georgia will win\n");
}
int main()
{freopen("t.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
for(int i=0;i<N;i++)
scanf("%d",&P[i]);
sort(P,P+N);
solve();
}
return 0;
}
POJ1704 Georgia and Bob Nim游戏的更多相关文章
- POJ1704 Georgia and Bob(Nim博弈变形)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14312 Accepted: 4840 ...
- POJ1704 Georgia and Bob
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9771 Accepted: 3220 Description Georg ...
- [POJ1704]Georgia and Bob 博弈论
从这开始我们来进入做题环节!作为一个较为抽象的知识点,博弈论一定要结合题目才更显魅力.今天,我主要介绍一些经典的题目,重点是去理解模型的转化,sg函数的推理和证明.话不多说,现在开始! Georgia ...
- POJ1704 Georgia and Bob (阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u Subm ...
- POJ1704 Georgia and Bob 题解
阶梯博弈的变形.不知道的话还是一道挺神的题. 将所有的棋子两两绑在一起,对于奇数个棋子的情况,将其与起点看作一组.于是便可以将一组棋子的中间格子数看作一推石子.对靠右棋子的操作是取石子,而对左棋子的操 ...
- POJ1704 Georgia and Bob 博弈论 尼姆博弈 阶梯博弈
http://poj.org/problem?id=1704 我并不知道阶梯博弈是什么玩意儿,但是这道题的所有题解博客都写了这个标签,所以我也写了,百度了一下,大概是一种和这道题类似的能转换为尼姆博弈 ...
- POJ 1704 Georgia and Bob (Nim游戏变形)
题目:http://poj.org/problem?id=1704 思路:Nim游戏策略,做如下转换,如果N是偶数,则两两配对,将两个数之间的格子数(距离)看做成这一堆石头的数量. 如果N是奇数,则将 ...
- 【POJ】1704 Georgia and Bob(Staircase Nim)
Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...
- POJ.1704.Georgia and Bob(博弈论 Nim)
题目链接 \(Description\) 一个1~INF的坐标轴上有n个棋子,给定坐标Pi.棋子只能向左走,不能跨越棋子,且不能越界(<1).两人每次可以将任意一个可移动的棋子向左移动一个单位. ...
随机推荐
- python字符串,常用编码
Python的字符串和编码 1.常用编码 与python有关的编码主要有:ASCII.Unicode.UTF-8 其中ASCII如今可以视作UTF-8的子集 内存中统一使用Unicode编码(如记事本 ...
- jQuery学习之------元素样式的操作
jQuery学习之------元素样式的操作 一..addClass( className )方法----增加样式 1.addClass( className ) : 为每个匹配元素所要增加的一个或多 ...
- CodeForcesGym 100524J Jingles of a String
Jingles of a String Time Limit: 2000ms Memory Limit: 524288KB This problem will be judged on CodeFor ...
- Archive log restore using RMAN for Logminer (http://www.dba-village.com/village/dvp_forum.OpenThread?ThreadIdA=26816)
Subject: Archive log restore using RMAN for Logminer Author: Edwin Weele van der, Netherlands Date: ...
- 【ZJOI2017 Round1练习&BZOJ5354】D7T3 room(DP)
题意: 思路: 写了两种版本 考场版本 ..,..]of longint; t:..,..]of longint; n,m,i,j,k,oo,ans,d1:longint; function min( ...
- baidu 和 es 使用
http://www.cnblogs.com/kangoroo/p/8047586.html
- CSU - 1333 1333: Funny Car Racing(spfa)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 这题多了一个限制条件是每一条路都会规律的开放a时间关闭b时间,车子必须在开放的时候进入,在关 ...
- CODEVS——T 3736 【HR】万花丛中2
http://codevs.cn/problem/3736/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description ...
- linux下crontab安装和使用(定时任务)
在Unix和Linux的操作系统之中,cron可以让系统在指定的时间,去执行某个指定的任务,crontab命令常用于管理对应的cron. 一.crontab在线安装 yum -y install vi ...
- 在 IIS 中承载 WCF 服务
本主题概述了创建 Internet 信息服务 (IIS) 中承载的 Windows Communication Foundation (WCF) 服务所需的基本步骤. 本主题假设您熟悉 IIS 且了解 ...