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

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

Home Page   Go Back  To top

这题做法真的666啊,不知道std是怎么想出来的

首先我们想到一种必败态:即仅有两个点且相邻

那么我们可以把所有的点排序之后两两捆绑,这样如果A移动第一个,那么B可以把第二个移动相同的步数

这样我们就解决了顺序的问题

那么接下来就考虑如何解决博弈问题

这里有个神仙操作

把两点直接的距离看做一堆石子,然后请Nim来就可以啦

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN=1e4+10,INF=1e9+10;
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();}
    while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘;c=getchar();}
    return x*f;
}
int a[MAXN];
int main()
{
    #ifdef WIN32
    freopen("a.in","r",stdin);
    #else
    #endif
    int QwQ=read();
    while(QwQ--)
    {
        int N=read();
        for(int i=1;i<=N;i++) a[i]=read();
        sort(a+1,a+N+1);
        int ans;
        if(N&1)//奇数
        {
            ans=a[1]-1;
            for(int i=3;i<=N;i+=2)
                ans=ans^(a[i]-a[i-1]-1);
        }
        else
        {
            ans=a[2]-a[1]-1;
            for(int i=4;i<=N;i+=2)
                ans=ans^(a[i]-a[i-1]-1);
        }
        if(ans) printf("Georgia will win\n");
        else printf("Bob will win\n");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/zwfymqz/p/8459698.html

时间: 2024-08-08 17:00:46

POJ 1704 Georgia and Bob(阶梯博弈)的相关文章

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

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

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

POJ 1704 Georgia and Bob(nim博弈论)

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

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,

[原博客] 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)

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

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