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

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

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


题解:

我们把相邻两给位置组成一对,如果N为奇数的话,就让第一个数和0组成一对,然后考虑每一对,无论前面的位置移动多少,后面一个点总能移动相同的距离使得两个点对之间的距离保持不变,所以我们就可以将每一对之间的距离拿出来,就变成了了这(N+1)/2个数之间的NIM博弈了,异或即可,很巧妙的一道题。

参考代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=;
int T,n,a[maxn],ans; int main()
{
scanf("%d",&T);
while(T--)////
{
scanf("%d",&n);
for(int i=;i<=n;++i) scanf("%d",&a[i]); sort(a+,a+n+);
ans=; a[]=;
for(int i=n;i>;i-=)
ans^=(a[i]-a[i-]-);
if(ans) puts("Georgia will win");
else puts("Bob will win");
} return ;
}

POJ1704 Georgia and Bob(Nim博弈变形)的更多相关文章

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

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

  2. POJ1704 Georgia and Bob Nim游戏

    POJ1704 这道题可以转化为经典的Nim游戏来解决. Nim游戏是这样的 有n堆石子,每堆各有ai个. 两个人轮流在任意石子堆中取至少1个石子,不能再取的输. 解决方法如下, 对N堆石子求异或 为 ...

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

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

  4. POJ1704 Georgia and Bob 题解

    阶梯博弈的变形.不知道的话还是一道挺神的题. 将所有的棋子两两绑在一起,对于奇数个棋子的情况,将其与起点看作一组.于是便可以将一组棋子的中间格子数看作一推石子.对靠右棋子的操作是取石子,而对左棋子的操 ...

  5. POJ1704 Georgia and Bob

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9771   Accepted: 3220 Description Georg ...

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

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

  7. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  8. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

  9. POJ Georgia and Bob-----阶梯博弈变形。

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

随机推荐

  1. python基础-匿名函数和内置函数

    匿名函数和内置函数 匿名函数:没有名字,使用一次即被收回,加括号就可以运行的函数. 语法:lambda 参数:返回值 使用方式: 将匿名函数赋值给变量,给匿名函数一个名字,使用这个变量来调用(还不如用 ...

  2. 在Debian/Ubuntu上面安装升级nginx到最新版

    在Debian下面通过 apt-get 可以自动安装 nginx,不过版本一般比较老,如果想要使用nginx的最新特性就需要升级版本.   一般安装可以通过编绎源文件安装,但可能需要安装很多编绎工具, ...

  3. Spring Boot Actuator监控使用详解

    在企业级应用中,学习了如何进行SpringBoot应用的功能开发,以及如何写单元测试.集成测试等还是不够的.在实际的软件开发中还需要:应用程序的监控和管理.SpringBoot的Actuator模块实 ...

  4. Spring-boot构建多模块依赖工程时,maven打包异常:程序包xxx不存在

    在qizhi项目改版的时候, 所有代码都迁移好了, 但是compile的时候报程序包*****不存在, 具体到某一个类就是: 找不到符号. 下面这篇文章是正解 http://hbxflihua.ite ...

  5. Nebula 架构剖析系列(二)图数据库的查询引擎设计

    摘要 上文(存储篇)说到数据库重要的两部分为存储和计算,本篇内容为你解读图数据库 Nebula 在查询引擎 Query Engine 方面的设计实践. 在 Nebula 中,Query Engine ...

  6. 在开发框架中扩展微软企业库,支持使用ODP.NET(Oracle.ManagedDataAccess.dll)访问Oracle数据库

    在前面随笔<在代码生成工具Database2Sharp中使用ODP.NET(Oracle.ManagedDataAccess.dll)访问Oracle数据库,实现免安装Oracle客户端,兼容3 ...

  7. ubuntu 16.04源码编译和配置caffe详细教程 | Install and Configure Caffe on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/b90033a9/,欢迎阅读! Install and Configure Caffe on ubuntu 16.04 Series ...

  8. Web Deploy远程发布

    前言 我们在使用VS开发.net网站的时候,部署时可能会遇到缺少dll的问题,每次都远程桌面登陆,然后拷贝过去,太麻烦了.我们可以使用Web Deploy这个远程部署工具,不仅部署容易了,也方便进行迭 ...

  9. java之初见

    1.Java语言的了解: Java语言最早是由SUN公司创造出来的,1991年,SUN公司的green项目,Oak,随后SUN公司和后来的甲骨文公司又先后发布了java1.0,1.1,1.2,1.3, ...

  10. springboot整合netty的多种方式

    netty作为一个高性能的io框架,是非好用的一个技术框架, Netty 是一个基于NIO的客户.服务器端编程框架,使用Netty 可以确保你快速和简单的开发出一个网络应用,例如实现了某种协议的客户. ...