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
----------------------------------------------------
题意:在一条直线的格子上放有一些棋子,两人可以轮流选择一个棋子向左移动,但不能跨过前面的棋子或到同一个,无法进行操作的人输(即所有棋子都被前后逼死,无法移动)。
分析:可以把两个棋子间的距离看做nim游戏中一堆石子的数量,移动即为取走一些石子,但如果格子上有奇数个棋子,此时无法凑成整堆的石子(即两两棋子算作一堆石子的话,会多出一个棋子),这时把0看做一个棋子即可。注意,题目给的棋子位置不是升序,需要自己排序。
P.s.这种问题也被称作Staircase Nim。
 #include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int t,n,p[];
scanf("%d",&t);
while(t--)
{ int x=;
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&p[i]);
if(n%!=) p[n++]=;
sort(p,p+n);
for(int i=;i<n-;i+=)
{
x^=(p[i+]-p[i]-);//不断异或棋子之间的差值,即nim中的石子数
}
if(x==) printf("Bob will win\n");
else printf("Georgia will win\n");
}
return ;
}

AC了,打卡:【POJ】1704 Georgia and Bob

【POJ】1704 Georgia and Bob(Staircase Nim)的更多相关文章

  1. 【POJ】1704.Georgia and Bob

    题解 感觉挺神奇的 我们把石子从后往前相邻的两个两两配对,这样他们之间的空格就相当于一堆石子 而配对后左边棋子移动,右边棋子也一定可以跟上取 转化成简单的nim游戏,最后只要看转化出的这(N - 1) ...

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

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

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

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

  4. 【POJ】2348 Euclid's Game(扩欧)

    Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first pl ...

  5. 【POJ】 1061 青蛙的约会(扩欧)

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 119148   Accepted: 25070 Descript ...

  6. 【POJ】1062 昂贵的聘礼 (最短路)

    题目 传送门:QWQ 分析 最短路显然,但不好搞地位等级..... 地位等级不好搞?那么就暴力.. 枚举我们允许的地位等级,跑最短路. 所以$ n^2logn $出100什么鬼啊,很有迷惑性啊 还有4 ...

  7. 【SPOJ】Longest Common Substring II (后缀自动机)

    [SPOJ]Longest Common Substring II (后缀自动机) 题面 Vjudge 题意:求若干个串的最长公共子串 题解 对于某一个串构建\(SAM\) 每个串依次进行匹配 同时记 ...

  8. 【BZOJ1717】产奶的模式(后缀数组)

    [BZOJ1717]产奶的模式(后缀数组) 题面 权限题 hihocoder 洛谷 题解 \(hihocoder\)里面讲的非常好了 这题要求的就是最长可重叠重复K次子串 所谓相同的子串 我们可以理解 ...

  9. 【BZOJ2154】Crash的数字表格(莫比乌斯反演)

    [BZOJ2154]Crash的数字表格(莫比乌斯反演) 题面 BZOJ 简化题意: 给定\(n,m\) 求\[\sum_{i=1}^n\sum_{j=1}^mlcm(i,j)\] 题解 以下的一切都 ...

随机推荐

  1. Python学习笔记4

    根据文件类型选择文件 文件 s s.split('.')[1] 即为文件后缀名,据此判断 输出执行后结果到指定文件 os.system('E:\\Learning\\python\\test_case ...

  2. [2013-07-22]varnish-cache 安装配置及体验笔记

    varnish安装 ubuntu12安装参考 其他系统参考 如果选择了直接从源安装的方式的话,就不要自己去编译了,以免出现意外(悲剧的我,varnishlog 有点问题,之前先编译安装了,再从源安装, ...

  3. node.js后台快速搭建在阿里云(二)(pm2和nginx篇)

    前期准备 阿里云服务器 node.js pm2 express nginx linux(推荐教程:鸟哥的私房菜) 简介 嗯……我只是个前端而已 在第一部分说完了express篇. 后面继续项目的部署, ...

  4. poj 3522 Kruskal

    题意:求图的一个生成树使其最大边权与最小边权的差值最小,求其最小值 思路:利用贪心思想,先对边进行排序,然后从最小边开始枚举,每次进行kruskal向右加入边,若加入边刚好能遍历所有点,记录最后加入的 ...

  5. JTemplates + $.Ajax

    上篇基础使用后: +AJAX 只需要改列名即可 :<script type="text/template" id="foreach">   里的循环 ...

  6. 我来给.Net设计一款HttpClient

    1前言 时间飞快,转眼半年,碌碌无为,眼下就要三十而立,回想三年前的今天,我将NetworkSocket库开放到github,一直在更新与学习,不求有这个库能有多好,只求自己在过程能成长,将领悟到一些 ...

  7. 5th-个人总结(Alpha阶段)

    一. 总结自己的Alpha过程 1.团队的整体情况 在团队中这次担任队长的职务. alpha阶段完成情况还算理想,大家都完成了指定的任务.但是也少不了犯错,一些需求没有划分的足够细致,后来功能完成后发 ...

  8. 201521123007《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 1. clone方法 1.1 Object ...

  9. 201521123070 《JAVA程序设计》第5周学习总结

    1. 本章学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. http://naotu.baidu.com/file/02b01f465e125c5942648a03358273b0 2. ...

  10. 201521123044 《Java程序设计》第2周作业-Java基本语法与类库

    1. 本章学习总结 ·1.浮点型的不精确,不能简单的像C语言一样用float或者double来定义.在java中有更精确的BigDecimal类. 举例:BigDecimal bd1= new Big ...