POJ - 1704 Georgia and Bob

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

#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int T, A[1010];
    scanf("%d", &T);
    while (T--) {
        int N, ans = 0;
        scanf("%d", &N);
        for (int i = 0; i < N; i++)
            scanf("%d", &A[i]);
        if (N % 2) A[N++] = 0;
        sort(A, A + N);

        for (int i = 1; i < N; i += 2)
            ans ^= A[i] - A[i-1] - 1;

        if (ans) puts("Georgia will win");
        else puts("Bob will win");
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-10 07:08:20

POJ - 1704 Georgia and Bob的相关文章

POJ 1704 Georgia and Bob(nim博弈论)

题目地址:POJ 1704 这个题实在巧妙..居然这样就可以转化成了经典的nim模型. 这题可以从左往右两两配对,如果是奇数个的话,就让最左边的与0配对.然后每当对方移动某一对的前一个,你总可以移动该对的后一个来移动回来.所以这是没有影响的.有影响的只是每一对中间的空格数.这就转化成了((n+1)/2)堆石子的游戏,每一堆的石子个数是每一对点之间的空格数.然后用异或求解. 代码如下: #include <iostream> #include <cstdio> #include &l

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

POJ 1704 题目链接 关于阶梯博弈有如下定理: 将所有奇数阶梯看作n堆石头,做Nim,将石头从奇数堆移动到偶数堆看作取走石头,同样地,异或值不为0(利己态)时,先手必胜. 定理证明看此博:http://blog.csdn.net/kk303/article/details/6692506 以下是POJ 1704的AC代码: //棋子只能往左走(最左有界线),可以走任意多格(>=1) //而且棋子不能越过在它前面的棋子(它左边的棋子) //每个格最多放一个棋子,说明棋子也不能走到另一个棋子所

poj 1704 Georgia and Bob(阶梯博弈)

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, ...

POJ 1704 Georgia and Bob(阶梯博弈)

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11357   Accepted: 3749 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 c

poj 1704 Georgia and Bob (nim)

题意: N个棋子,位置分别是p[1]...p[N]. Georgia和Bob轮流,每人每次可选择其中一个棋子向左移动若干个位置(不能超过前一个棋子,不能超出最左边[位置1]且不能不移) Georgia先手,问谁赢. 思路: 将棋子按位置从右到左两个两个作为一对.若棋子总个数是奇数,将第一个棋子和[位置0]作为一对.(可想象位置0放了一个棋子). 情况一:先手若移动某对棋子中的第一个棋子K位,则后手可将该对棋子中的第二个棋子也移动K位.即这种情况不对结果产生影响. 情况二:先手若移动某对棋子中的第

[原博客] POJ 1704 Georgia and Bob

题目链接题意:如图,Georgia和Bob在玩游戏.一个无限长的棋盘上有N个旗子,第i个棋子的位置可以用Pi表示.现在Georgia先走.每个人每一次可以把一枚棋子向左移动任意个格子,但是不能超越其他棋子,也不能和其他棋子处在同一个格子里.如果轮到某一个人的时候Ta再也不能移动棋子了,就判负.现在每个测试数据给定一种情况,如果Georgia会赢,输出“Georgia will win”,如果Bob会赢,输出“Bob will win”,如果不确定,输出“Not sure”.两个人都知道获胜策略是

POJ 1704 Georgia and Bob [阶梯Nim]

题意: 每次可以向左移动一个棋子任意步,不能跨过棋子 很巧妙的转化,把棋子间的空隙看成石子堆 然后裸阶梯Nim #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long ll; const int N=1005; inline int re

poj 1704 Georgia and Bob 博弈

排成一条直线的格子上有n个棋子,两个人每个人每次可以选择一枚棋子向左移动任意步数,但是不可以越过棋子,无法进行操作的一方失败,问谁会失败. 先考虑偶数个棋子时的情况,将棋子从左到右两两配对,转化成n/2堆石子,每堆石子的个数为中间的空格数,这样每次向左移动可以看做在一堆石子中取了任意个,转换成了nim博弈,两两配对的石子中的左面的石子如果向左移动,那么相当于石子的数目会增加,但不会改变胜负状态,因为下一个人可以移动右面的石子来抵消. #include <cstdio> #include <

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

题意:有一个一维棋盘,有格子标号1,2,3,......有n个棋子放在一些格子上,两人博弈,只能将棋子向左移,不能和其他棋子重叠,也不能跨越其他棋子,不能超越边界,不能走的人输 思路:可以用阶梯博弈来做. 那么先简单讲一下阶梯博弈: 有一个x阶阶梯,每一阶都有一定数量的石头,每次只能把某一阶梯上任意数量(不为0)的石头往下移动一阶,最多只能移动到地面,不能移动的败.这里先手的策略是这样:对奇数阶阶梯的石子进行Nim博弈,异或和为0必败.为什么不用考虑偶数呢?因为如果后手的人把m颗石头从2*n阶移