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. EL标签和JSTL标签---JSP页面的应用

    ====EL(Expression Language)表达式语言:用于计算和输出存储在标志位置(page.request.session.application)的java对象的值: 1.开启和关闭E ...

  2. oracle的学习 第二节:创建数据表

    学习内容: A.创建数据库和表空间 B.创建用户和分配权限 C.创建数据表 一.创建数据库和表空间 (一)SQL语言的基本概念 1.概念 高级的结构化查询语言:沟通数据库服务器和客户的重要桥梁. PL ...

  3. linux启动黑屏或无法进入会话管理器

    原因是因为更新软件时删除了/etc中的xserver配置文件,进入livecd将相关文件拷贝即可

  4. 第1条:了解Objective-C 语言的起源

    1.OC语言是由Smalltalk演化而来.该语言使用“消息结构” 而 非“函数调用”. 使用“消息结构”的语言,其运行时所执行的代码由运行环境来决定: 编译器不需要关心接收消息的对象是什么类型,只在 ...

  5. Windows Phone 之播放视频

    在Windows Phone 7中播放视频有两种方式, (1)使用MediaElement 控件来播放:用MediaElement 控件来播放视频比较灵活,你需要自己去实现播放暂停进度条等等的功能,播 ...

  6. hibernate中一对多 多对多 inverse cascade

    ----------------------------一对多------------------------------------------- inverse属性:是在维护关联关系的时候起作用的 ...

  7. Fedora 21 安装桌面环境

    Mate桌面环境:$ sudo yum install @mate-desktop KDE桌面环境:$ sudo yum install @kde-desktop XFCE桌面环境:$ sudo yu ...

  8. PHPCMS GET标签使用

    大纲: get 标签概述get 标签语法get 标签创建工具get 调用本系统示例get 调用其他系统示例一.get 标签概述    通俗来讲,get 标签是Phpcms定义的能直接调用数据库里面内容 ...

  9. In Place Upgrade of CentOS 6 to CentOS 7

    Note: This is not the most highly recommended method to move from CentOS 6 to CentOS 7 ... but it ca ...

  10. django框架的网站发布后设置是否允许被别人iframe引用

    例如: <iframe src="http://127.0.0.1:8008" style="width:100%;height:400px;">& ...