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

[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+,INF=1e9+;
inline int read()
{
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';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=;i<=N;i++) a[i]=read();
sort(a+,a+N+);
int ans;
if(N&)//奇数
{
ans=a[]-;
for(int i=;i<=N;i+=)
ans=ans^(a[i]-a[i-]-);
}
else
{
ans=a[]-a[]-;
for(int i=;i<=N;i+=)
ans=ans^(a[i]-a[i-]-);
}
if(ans) printf("Georgia will win\n");
else printf("Bob will win\n");
}
return ;
}

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

  1. POJ 1704 Georgia and Bob [阶梯Nim]

    题意: 每次可以向左移动一个棋子任意步,不能跨过棋子 很巧妙的转化,把棋子间的空隙看成石子堆 然后裸阶梯Nim #include <iostream> #include <cstdi ...

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

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

  3. hdu 4315 Climbing the Hill && poj 1704 Georgia and Bob阶梯博弈--尼姆博弈

    参考博客 先讲一下Georgia and Bob: 题意: 给你一排球的位置(全部在x轴上操作),你要把他们都移动到0位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...

  4. poj 1704 Georgia and Bob (nim)

    题意: N个棋子,位置分别是p[1]...p[N]. Georgia和Bob轮流,每人每次可选择其中一个棋子向左移动若干个位置(不能超过前一个棋子,不能超出最左边[位置1]且不能不移) Georgia ...

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

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

  6. POJ.1704.Georgia and Bob(博弈论 Nim)

    题目链接 \(Description\) 一个1~INF的坐标轴上有n个棋子,给定坐标Pi.棋子只能向左走,不能跨越棋子,且不能越界(<1).两人每次可以将任意一个可移动的棋子向左移动一个单位. ...

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

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

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

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

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

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

随机推荐

  1. PHP全栈学习笔记18

    php基础知识,JavaScript,jQuery,ajax基础知识 linux基础知识,mysql数据库的基础与优化 程序设计,PHP框架基础知识,算法,逻辑思维,高并发 PHP基础知识 引用变量, ...

  2. [node.js] fs.renameSync()报错

    初学node.js,跟着node入门,操作了一遍.在最后一步,上传图片并显示时遇到报错 fs.js: throw err; ^ Error: ENOENT: no such file or direc ...

  3. pocketsphinx 移植问题解决备案

    一 编译问题: 1 _continuous: error while loading shared libraries: libpocketsphinx.so.3: cannot open share ...

  4. thymeleaf-在font标签中的使用

    <font color="red" th:text="开始了">font外</font>页面显示红色字体 开始了 (同时存在,则前者覆盖 ...

  5. H5在WebView上开发小结

    背景 来自我司业务方要求,需开发一款APP.但由于时间限制,只能采取套壳app方式,即原生app内嵌webview展示前端页面.本文主要记述JavaScript与原生app间通信,以及内嵌webvie ...

  6. 《JavaScript总结》apply、call和bind方法

    在JavaScript中,apply.call.bind这个三个方法,它们的作用都是为了改变某个函数运行时的上下文, 也就是改变函数体内的this指向. 在一个函数里,存在“定义时上下文”.“运行时上 ...

  7. TCP/IP 笔记 - TCP保活机制

    TCP协议中不存在轮询机制,这意味着加入启动一个客户端进程,与服务器建立连接后,然后离开几小时.几天.甚至几个月,连接依然会保持着.理论上,中间路由器可以崩溃和重启,数据线可以断开再连接,只要连接两端 ...

  8. Jvm运行时数据区

    一:运行时数据区 Java虚拟机在执行Java程序的过程中会把它管理的内存分为若干个不同的数据区域.这些区域有着各自的用途,一级创建和销毁的时间,有的区域随着虚拟机进程的启动而存在,有些区域则依赖用户 ...

  9. 如何像Python高手(Pythonista)一样编程

    最近在网上看到一篇介绍Pythonic编程的文章:Code Like a Pythonista: Idiomatic Python,其实作者在2006的PyCon会议后就写了这篇文章,写这篇文章的主要 ...

  10. 再也不用被this苦恼了

    前端编程对于this再熟悉不过了,今日来个老调重弹温故知新,肯定有很多大佬已经完全吃透了this原理,敬请出门左拐.对于理解this似懂非懂的同学可以借鉴一波 1.this描述 this指的是当前执行 ...