[POJ1704]Georgia and Bob

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8552   Accepted: 2704

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

POJ Monthly--2004.07.18

Thinking

  可以转变成一个Nim问题。把棋子两两成对进行考虑,分成两组,每组的Nim值即为棋子之间的间隔数。

  右移视为减小Nim值,左边棋子左移视为增加Nim值,然而不管怎么增加,对手总有办法将其恢复,所以必胜态和必败态和Nim游戏相同。

  当棋子个数为奇数时,需要把第一个棋子和他前面的空格分为一组,剩下的分为一组即可。

var a:array[0..10000] of longint;
    n,i,t:longint;

procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

procedure main();
var x,i,j:longint;
begin
    fillchar(a,sizeof(a),0);
    readln(n);
    for i:=1 to n do
        read(a[i]);
    sort(1,n);
    x:=0;
    j:=1;
    if (n mod 2=1) then
        begin
            x:=a[1]-1;
            inc(j);
        end;
    while j<=n do
        begin
            x:=x xor(a[j+1]-a[j]-1);
            inc(j,2);
        end;
    if x=0 then writeln(‘Bob will win‘)
    else writeln(‘Georgia will win‘);
end;

begin
    readln(t);
    for i:=1 to t do main();
end.

时间: 2025-01-19 23:37:20

[POJ1704]Georgia and Bob的相关文章

POJ1704 Georgia and Bob (阶梯博弈)

Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Submit Status 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,

poj1704 Georgia and Bob(阶梯博弈)

Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9291   Accepted: 3021 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, ...

$POJ1704\ Georgia\ and\ Bob$ 博弈论

正解:博弈论 解题报告: 传送门! 啊先放下翻译趴$QwQ$大概就是说,有一行$1\cdot n$的网格,每次可以向左移动若干步,不能越过前面已有棋子的格子就是了,然后谁不能动就输了,问最后是先手必胜还是后手必胜 然后这就是个阶梯游戏的变式昂$QwQ$ 首先可以发现,当移动一个棋子的时候,相当于和后面那个棋子的距离变大,然后和前面那个棋子的距离变小,而且总量依然是不变的 于是考虑将所有棋子按升序排列,不难发现这题就变成了一个阶梯游戏?就因为只考虑间距,那每次移动都相当于是有一个减小了然后相邻那个

POJ1704 Georgia and Bob 题解

阶梯博弈的变形.不知道的话还是一道挺神的题. 将所有的棋子两两绑在一起,对于奇数个棋子的情况,将其与起点看作一组.于是便可以将一组棋子的中间格子数看作一推石子.对靠右棋子的操作是取石子,而对左棋子的操作并不会对游戏造成影响,考虑如果在 NIM 博弈时有增加石子的操作,那么下一步另一个人就可以去相同数量的石子,于是局面并没有改变. 然后就来一发异或和就行了. #include <bits/stdc++.h> using namespace std; int n,a[10005]; int mai

【POJ1704】Georgia and Bob(博弈论)

[POJ1704]Georgia and Bob(博弈论) 题面 POJ Vjudge 题解 这种一列格子中移动棋子的问题一般可以看做成一个阶梯博弈. 将一个棋子向左移动时,它和前面棋子的距离变小,和后面棋子的距离变大,并且减小的值和增大的值是相等的,因此,这个过程我们就可以等价成一个阶梯博弈了. #include<cstdio> #include<iostream> #include<algorithm> using namespace std; int a[1010

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(阶梯博弈)

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

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