Georgia and Bob
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 6622   Accepted: 1932

Description

Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, ..., and place N chessmen on different grids, as shown in the following figure for example: 

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

The 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

For 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

 /*

 如上如图所示:排成直线的格子上有n个格子,棋子i在左数第pi个格子上。
G和B轮流选择一个棋子向左移动。每次移动可以移动一格及以上任意多个格,
但是不允许超其他的格子,也不允许将两个棋子放在同一个格子内。
无法移动就失败了。~~ 转化:
如果将棋子两两看出一个整体考虑,我们就可以把这个游戏转为Nim游戏。
先将棋子的个数的奇偶分情况讨论。
偶数:___1____5____8______10
就可以转化为 第一堆 5-1-1=3 个
第二堆 10-8-1=1 个。 为什么能这样转化?
考虑其中的一对棋子,将右边的棋子向左移动就相当于从Nim的石子堆中
取走石子
另一方面,将左边的棋子向左移动,石子的数量就增加了。这就与Nim不同。
但是,即便对手增加了石子的数量,只要将所加部分减回去就回到了原来的
状态;即便增加了石子的数量,只要对手将所加的部分减回去也就回到原来
状态了。 奇数:将最左边的0看出起始点就转化成偶数个了。
*/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std; int f[];
int main()
{
int T,n,i,k,hxl;
while(scanf("%d",&T)>)
{
while(T--)
{
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d",&f[i]);
if(n%==)
f[++n]=;
k=;
sort(f+,f++n);
for(i=n;i>=;i=i-)
k=k^(f[i]-f[i-]-);
if(k==)
printf("Bob will win\n");
else printf("Georgia will win\n");
}
}
return ;
}

POJ Georgia and Bob-----阶梯博弈变形。的更多相关文章

  1. poj 1704 Georgia and Bob(阶梯博弈)

    Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9363   Accepted: 3055 D ...

  2. hdu 4315 Climbing the Hill && poj 1704 Georgia and Bob阶梯博弈--尼姆博弈

    参考博客 先讲一下Georgia and Bob: 题意: 给你一排球的位置(全部在x轴上操作),你要把他们都移动到0位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...

  3. POJ1704 Georgia and Bob (阶梯博弈)

    Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Subm ...

  4. POJ1704 Georgia and Bob(Nim博弈变形)

    Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14312   Accepted: 4840 ...

  5. HDU 4315 阶梯博弈变形

    n个棋子,其中第k个是红色的,每个棋子只能往上爬,而且不能越过.重叠其他棋子,谁将红色棋子移到顶部谁赢. 由于只能往上爬,所以很像阶梯博弈.这题有2个限制,棋子不能重叠,有红棋存在 首先不考虑红色棋, ...

  6. HDU 3389 阶梯博弈变形

    n堆石子,每次选取两堆a!=b,(a+b)%2=1 && a!=b && 3|a+b,不能操作者输 选石子堆为奇数的等价于选取步数为奇数的,观察发现 1 3 4 是无法 ...

  7. POJ 1704 Georgia and Bob(阶梯Nim博弈)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11357   Accepted: 3749 Description Geor ...

  8. POJ 1704 Georgia and Bob [阶梯Nim]

    题意: 每次可以向左移动一个棋子任意步,不能跨过棋子 很巧妙的转化,把棋子间的空隙看成石子堆 然后裸阶梯Nim #include <iostream> #include <cstdi ...

  9. POJ 1704 Georgia and Bob【博弈】

    题目链接: http://poj.org/problem?id=1704 题意: 给定棋子及其在格子上的坐标,两个人轮流选择一个棋子向左移动,每次至少移动一格,但是不可以碰到其他棋子.无路可走的时候视 ...

随机推荐

  1. JS:事件委托

    事件委托 事件流 事件流描述的是从页面中接收事件的顺序.---JS高级程序设计(第3版) DOM Level 2 Events规定的事件流有三个阶段:①事件捕获阶段.②处于目标阶段.③事件冒泡阶段 事 ...

  2. Inno Setup入门(二十三)——Inno Setup类参考(9)

    今天就简单说一下ProgressBar. TNewProgressBar = class(TWinControl)   property Min: Longint; read write;   pro ...

  3. RabbitMq qos prefetch 消息堵塞问题

    mq是实现代码扩展的有利手段,个人喜欢用概念来学习新知识,介绍堵塞问题的之前,先来段概念的学习. ConnectionFactory:创建connection的工厂类 Connection: 简单理解 ...

  4. JVM-垃圾收集算法、垃圾收集器、内存分配和收集策略

    对象已死么? 判断一个对象是否存活一般有两种方式: 1.引用计数算法:每个对象都有一个引用计数属性,新增一个引用时计数加1,引用释放时计数减1.计数为0时可以回收. 2.可达性分析算法(Reachab ...

  5. 【链表】Rotate List(三个指针)

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...

  6. Windows 8的语音识别

    不多说,直接干货! 第一步:启动windows 语音识别窗口 第二步:设置windows 语音识别窗口 第三步:使用windows 语音识别窗口来输入文字  成功!!! 欢迎大家,加入我的微信公众号: ...

  7. Android开发之漫漫长途 Ⅲ——Activity的显示之Window和View(2)

    该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...

  8. 中小团队快速构建SQL自动审核系统

    SQL审核与执行,作为DBA日常工作中相当重要的一环,一直以来我们都是通过人工的方式来处理,效率低且质量没办法保证.为了规范操作,提高效率,我们决定引入目前市面上非常流行的SQL自动审核工具Incep ...

  9. MySQL命令行导入导出数据

    参考:http://www.cnblogs.com/xcxc/archive/2013/01/30/2882840.html 这篇文章写得非常好,又简洁,而且深入浅出,排版也非常好看,不会像网上的只是 ...

  10. java 序列化与解序列化

    小例 import java.io.*; public class Box implements Serializable{ private int width; private int height ...