Georgia and Bob
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8656   Accepted: 2751

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

【思路】

阶梯博弈

将棋子之间的间距视作一堆石子,则问题可以转化为一类名为阶梯博弈的东西。

即:

如果对方在奇数位上取硬币,那么我们也类似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(阶梯博弈)的更多相关文章

  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. POJ 1704 Georgia and Bob(阶梯Nim博弈)

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

  4. POJ 1704 Georgia and Bob【博弈】

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

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

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

  6. POJ 1704 Georgia and Bob(阶梯博弈+证明)

    POJ 1704 题目链接 关于阶梯博弈有如下定理: 将所有奇数阶梯看作n堆石头,做Nim,将石头从奇数堆移动到偶数堆看作取走石头,同样地,异或值不为0(利己态)时,先手必胜. 定理证明看此博:htt ...

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

    题意:有一个一维棋盘,有格子标号1,2,3,......有n个棋子放在一些格子上,两人博弈,只能将棋子向左移,不能和其他棋子重叠,也不能跨越其他棋子,不能超越边界,不能走的人输 思路:可以用阶梯博弈来 ...

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

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

  9. POJ.1704.Georgia and Bob(博弈论 Nim)

    题目链接 \(Description\) 一个1~INF的坐标轴上有n个棋子,给定坐标Pi.棋子只能向左走,不能跨越棋子,且不能越界(<1).两人每次可以将任意一个可移动的棋子向左移动一个单位. ...

随机推荐

  1. [条形码] BarCodeToHTML条码生成类 (转载)

    点击下载 BarCodeToHTML.zip 过多的我就不多说了大家直接看代码吧,这是一个帮助大家生成条码的类,大小大家可以自由的设定 /// <summary> /// 类说明:条码生成 ...

  2. 额定能量不得超过160Wh, 等同是多少mAh电池容量?

    额定能量不得超过160Wh, 等同是多少mAh电池容量?行动电源容量标示, 正确应该是用Whr(Wh)瓦特小时来标示, 不过坊间标榜行动电源的容量通常是用xx000mAhWHr瓦特小时, 即是行动电源 ...

  3. js--Ajax的小知识(二):处理ajax的session过期的请求

    问题的产生: 现如今Ajax在Web项目中应用广泛,几乎可以说无处不在. 有时会碰到这样个问题:当Ajax请求遇到Session超时,应该怎么办? 显而易见,传统的页面跳转在此已经不适用,因为Ajax ...

  4. 判断用户输入是否为int整型方法之一!

    ; string vv = this.textBox2.Text; if (int.TryParse(vv, out age)) { age = int.Parse(this.textBox2.Tex ...

  5. 配置wamp开发环境【2】 配置wamp开发环境之mysql的配置

    此前我已经将wamp配置的Apache.PHP.phpmyadmin全部配置完成,以上三种配置参照 配置wamp开发环境 下面我们来看看mysql的配置,这里用的是mysql5.5.20,下载地址: ...

  6. 转: angularjs 指令中动态编译的方法(适用于有异步请求的情况) 内嵌指令无效

    angular的坑很多 例子: 在directive的link中有一个$http请求,当请求完成后根据返回的值动态做element.append('......');这个操作, 能显示没问题,可问题是 ...

  7. 使用ArrayList对大小写字母的随机打印

    从a~z以及A~Z随机生成一个字母并打印:打印全部的字母 package com.liaojianya.chapter1; import java.util.ArrayList; /** * This ...

  8. Java虚拟机类加载初始化解析

    Classloader的作用,概括来说就是将编译后的class装载.加载到机器内存中,为了以后的程序的执行提供前提条件. 一段程序引发的思考: 风中叶老师在他的视频中给了我们一段程序,号称是世界上所有 ...

  9. 【转】关于C的未定义行为

    关于C的未定义行为 转自:http://www.guokr.com/blog/471312/ 对于C的初学者来说,被要求做下面的这种题目真的是脑残的不能再脑残的行为.但是很多C初级教程——居然都有这样 ...

  10. 上传图片预览 支持IE8+,FF,Chrome ,保留原图片比例

    代码及效果:链接