poj 1704 Georgia and Bob(阶梯博弈)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 8656 | Accepted: 2751 |
Description

Georgia and Bob move the chessmen in turn. Every time a player will
choose a chessman, and move it to the left without going over any other
chessmen or across the left edge. The player can freely choose number of
steps the chessman moves, with the constraint that the chessman must be
moved at least ONE step and one grid can at most contains ONE single
chessman. The player who cannot make a move loses the game.
Georgia always plays first since "Lady first". Suppose that Georgia
and Bob both do their best in the game, i.e., if one of them knows a way
to win the game, he or she will be able to carry it out.
Given the initial positions of the n chessmen, can you predict who will finally win the game?
Input
first line of the input contains a single integer T (1 <= T <=
20), the number of test cases. Then T cases follow. Each test case
contains two lines. The first line consists of one integer N (1 <= N
<= 1000), indicating the number of chessmen. The second line contains
N different integers P1, P2 ... Pn (1 <= Pi <= 10000), which are
the initial positions of the n chessmen.
Output
each test case, prints a single line, "Georgia will win", if Georgia
will win the game; "Bob will win", if Bob will win the game; otherwise
'Not sure'.
Sample Input
2
3
1 2 3
8
1 5 6 7 9 12 14 17
Sample Output
Bob will win
Georgia will win
Source
【思路】
阶梯博弈
将棋子之间的间距视作一堆石子,则问题可以转化为一类名为阶梯博弈的东西。
即:
如果对方在奇数位上取硬币,那么我们也类似nim在奇数位上取硬币使SG值回到0;
如果对方在偶数位上取硬币。那么我们就把他刚刚从偶数位上传到奇数位上的硬币数。
原封不动的再传回偶数位。这样就可以保持SG=0;
因此把阶梯问题看作奇数项的Nim游戏。
【代码】
#include<cstdio>
#include<algorithm>
using namespace std; int a[],n; int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
int ans=,s=;
for(int i=n;i>;i-=)
ans^=a[i]-a[i-]-;
if(ans) puts("Georgia will win");
else puts("Bob will win");
}
return ;
}
poj 1704 Georgia and Bob(阶梯博弈)的更多相关文章
- poj 1704 Georgia and Bob(阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9363 Accepted: 3055 D ...
- hdu 4315 Climbing the Hill && poj 1704 Georgia and Bob阶梯博弈--尼姆博弈
参考博客 先讲一下Georgia and Bob: 题意: 给你一排球的位置(全部在x轴上操作),你要把他们都移动到0位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...
- POJ 1704 Georgia and Bob(阶梯Nim博弈)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11357 Accepted: 3749 Description Geor ...
- POJ 1704 Georgia and Bob【博弈】
题目链接: http://poj.org/problem?id=1704 题意: 给定棋子及其在格子上的坐标,两个人轮流选择一个棋子向左移动,每次至少移动一格,但是不可以碰到其他棋子.无路可走的时候视 ...
- POJ 1704 Georgia and Bob [阶梯Nim]
题意: 每次可以向左移动一个棋子任意步,不能跨过棋子 很巧妙的转化,把棋子间的空隙看成石子堆 然后裸阶梯Nim #include <iostream> #include <cstdi ...
- POJ 1704 Georgia and Bob(阶梯博弈+证明)
POJ 1704 题目链接 关于阶梯博弈有如下定理: 将所有奇数阶梯看作n堆石头,做Nim,将石头从奇数堆移动到偶数堆看作取走石头,同样地,异或值不为0(利己态)时,先手必胜. 定理证明看此博:htt ...
- POJ 1704 Georgia and Bob(阶梯博弈)题解
题意:有一个一维棋盘,有格子标号1,2,3,......有n个棋子放在一些格子上,两人博弈,只能将棋子向左移,不能和其他棋子重叠,也不能跨越其他棋子,不能超越边界,不能走的人输 思路:可以用阶梯博弈来 ...
- POJ1704 Georgia and Bob (阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u Subm ...
- POJ.1704.Georgia and Bob(博弈论 Nim)
题目链接 \(Description\) 一个1~INF的坐标轴上有n个棋子,给定坐标Pi.棋子只能向左走,不能跨越棋子,且不能越界(<1).两人每次可以将任意一个可移动的棋子向左移动一个单位. ...
随机推荐
- spring 的 PropertyPlaceholderConfigurer读取的属性怎么访问 (java访问方式,不是xml中的占位符哦)及此类的应用
一.1.占位符的应用:(@Autowired注解方式,不需要建立set与get方法了,xml注入也不需要写了) http://www.cnblogs.com/susuyu/archive/2012/0 ...
- Oracle RAC OCR 和 VotingDisk 的备份与恢复
一:Voting DiskVoting Disk 这个文件主要用于记录节点成员状态,在出现脑裂时,决定那个Partion获得控制权,其他的Partion必须从集群中剔除.Voting disk使用的是 ...
- 深入理解shared pool共享池之library cache的library cache pin系列三
关于library cache相关的LATCH非常多,名称差不多,我相信一些人对这些概念还是有些晕,我之前也有些晕,希望此文可以对这些概念有个更为清晰的理解,本文主要学习library cache p ...
- Windows phone 之XML序列化与反序列化
为什么要做序列化和反序列化? 一个回答: 我们都知道对象是不能在网络中直接传输的,不过还有补救的办法.XML(Extensible Markup Language)可扩展标记语言,本身就被设计用来存储 ...
- Git (2)
要使用Git首先遇到的问题是怎么把文件加到库中. 很简单. 新建一个目录,然后git init. 完成上述工作之后的唯一改动是在当前目录下生成了一个.git的子目录.这个子目录是一个集中的数据库,包含 ...
- [转] CSS direction属性简介与实际应用 ---张鑫旭
一.用的少并不代表没有用 至少,在我接触的这么多项目里,没有见到使用过CSS direction属性做实际开发的. 为什么呢?是因为direction长得丑吗? 虽然说direction确实其貌不扬, ...
- js 中对象--对象结构(原型链基础解析)
对于本篇对于如何自定义对象.和对象相关的属性操作不了解的话,可以查我对这两篇博客.了解这两篇可以更容易理解本篇文章 用构造函数创建了一个对象 obj对象的本身创建了两个属性 x=1 ,y=2 ...
- 关闭linux终端命令行退格报警声(centos7亲测有效)
首先这个声音不是外置音频设备发出,而是主板上的蜂鸣器 1,使用root账户登录 2,vi 打开 ~/.bashrc 脚本 3,在脚本的最后一行加上 setterm -blength 0 4,保存脚本 ...
- JavaScript学习心得(八)
Cookie是Netscape发明的技术,是动态网站必不可少的部分,用于浏览器请求Web页面的超文本传输协议是一种无状态的协议. 两种方法维护状态:使用会话(session)(使用服务器技术实现,数据 ...
- MyEclipse使用经验总结
0.快捷键 ================================================================================ 编辑: Ctrl+Shif ...