Georgia and Bob
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7233   Accepted: 2173

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游戏,两个石子之间的间隔就是石子个数
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAX_N = ;
int p[MAX_N]; int main()
{
int t;
scanf("%d",&t);
while(t--) {
int N;
scanf("%d",&N);
for(int i = ; i < N; ++i) {
scanf("%d",&p[i]);
}
if(N % == ) p[N++] = ;
sort(p, p + N); int x = ;
for(int i = ; i + < N; i += ) {
x ^= (p[i + ] - p[i] - );
} if(x == ) printf("Bob will win\n");
else printf("Georgia will win\n");
}
//cout << "Hello world!" << endl;
return ;
}

poj 1704的更多相关文章

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

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

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

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

  3. 阶梯博弈&POJ 1704

    阶梯博弈: 先借用别人的一幅图片.(1阶梯之前还有一个0阶梯未画出) 阶梯博弈的最初定义是这样的:每一个阶梯只能向它的前一个阶梯移动本阶梯的点,直至最后无法移动的为输. 那么,利用NIM,只计算奇数级 ...

  4. POJ 1704 Georgia and Bob (Nim游戏变形)

    题目:http://poj.org/problem?id=1704 思路:Nim游戏策略,做如下转换,如果N是偶数,则两两配对,将两个数之间的格子数(距离)看做成这一堆石头的数量. 如果N是奇数,则将 ...

  5. POJ 1704 Georgia and Bob【博弈】

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

  6. 【POJ 1704】 Georgia and Bob

    [题目链接] http://poj.org/problem?id=1704 [算法] 阶梯博弈 [代码] #include <algorithm> #include <bitset& ...

  7. 【poj 1704】Georgia and Bob

    Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9776 Accepted: 3222 Description Georgia a ...

  8. poj 1704 阶梯博弈

    转自http://blog.sina.com.cn/s/blog_63e4cf2f0100tq4i.html 今天在POJ做了一道博弈题..进而了解到了阶梯博弈...下面阐述一下我对于阶梯博弈的理解. ...

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

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

随机推荐

  1. Node.js学习笔记 02 Implementing flow control

    What is flow control? 和其它语言一样,Node.js 在代码编写时,如何组织代码,如何写出clean code都是不可避免的难点. 同时,由于Node.js的天然特性(异步,事件 ...

  2. char const*, char*const, const char *const的区别

    C++标准规定,const关键字放在类型或变量名之前等价的.所以,const char*和 char const*是一样的. const char*   //常量指针---指向常量的指针----指针指 ...

  3. C#串口操作类,包括串口读写操作

    串口进行操作的类,其中包括写和读操作,类可设置串口参数.设置接收函数.打开串口资源.关闭串口资源,操作完成后,一定要关闭串口.接收串口数据事件.接收数据出错事件.获取当前全部串口.把字节型转换成十六进 ...

  4. Python sequence (序列)

    序列简介 sequence 是一组有序元素的组合 序列可以是多个元素,也可以一个元素都没有 序列有2种:tuple(定值表).List(表) D:\python\Python_Day>pytho ...

  5. poj 3580 SuperMemo

    题目连接 http://poj.org/problem?id=3580 SuperMemo Description Your friend, Jackson is invited to a TV sh ...

  6. Objective-C 一些概念

    Automatic Reference Counting (ARC)

  7. 位bit——字节Byte???

    1.换算 每8个位(bit)组成一个字节(byte) 位bit简写为小写字母“b”,字节Byte简写为大写字母“B” 8*b=1*B 1024*B=1*KB 1024*K=1MB 2.举例 一个英文字 ...

  8. Why does uitableview cell remain highlighted?

    What would cause a tableview cell to remain highlighted after being touched? I click the cell and ca ...

  9. html5之canvas练习

    代码地址:github.com/peng666/blogs 在线地址:http://peng666.github.io/blogs/

  10. 两个SVN仓库之间代码的转移

    背景: 1.公司的svn服务器架设在了公司内网环境中,没有公网ip,所以离开了公司环境就无法访问(更新.提交...)svn服务器了: 2.四个开发人员去客户现场开发新的需求,在现场找了一台服务器临时搭 ...