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. C++的访问关系

    1.C++的访问关系

  2. 记录初学Spring boot中使用GraphQL编写API的几种方式

    Spring boot+graphql 一.使用graphql-java-tools方式 <dependency> <groupId>com.graphql-java-kick ...

  3. 898. Bitwise ORs of Subarrays

    We have an array A of non-negative integers. For every (contiguous) subarray B = [A[i], A[i+1], ..., ...

  4. Qt5学习笔记(基础)

    按钮 #include <QApplication> /*应用程序抽象类*/ #include <QWidget> //窗口类 #include <QPushButton ...

  5. 记录php漏洞--宇宙最强语言 PHP 爆出 DoS 漏洞,可以直接灌满 CPU

    站长之家(Chinaz.com)5月20日消息  近日,PHP被爆出存在远程DOS漏洞,若黑客利用该漏洞构造PoC发起连接,容易导致目标主机CPU被迅速消耗.此漏洞涉及众多PHP版本,因而影响范围极大 ...

  6. 怎样使用Navicat Premium导出导入mysql数据库

    首先,在Navicat Premium中连接要导出数据库的mysql数据库. 2 1.填写好连接数据库的信息后就可以连接到需要导出的数据库了. 3 打开要导出的数据库. 4 将数据库的结构和数据导出为 ...

  7. Highcharts纯Javascript图表使用讲解

    Highcharts提供大量的选项配置参数,您可以轻松定制符合用户要求的图表,目前官网只提供英文版的开发配置说明文档,而中文版的文档网上甚少,且零散不全.这里,我把Highcharts常用的最核心的参 ...

  8. sehll-011:case脚本的基本用法

    ##  注意判断的括号里的用法, 变量用双引号,且括号后面带空格.否则可能会有报错. #!/bin/bash # 我们可以认为1-3是三个不同的大脚本.我这里用简单的命令代替. echo " ...

  9. 【DB2】How to resolve SQL20249N the statement was not processed with error

    相关链接 https://vinaysdb2blog.blogspot.com/2017/11/how-to-resolve-sql20249n-statement-was-not-processed ...

  10. Spring Security构建Rest服务-1204-Spring Security OAuth开发APP认证框架之Token处理

    token处理之一基本参数配置 处理token时间.存储策略,客户端配置等 以前的都是spring security oauth默认的token生成策略,token默认在org.springframe ...