Georgia and Bob
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 14312   Accepted: 4840

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


题解:

我们把相邻两给位置组成一对,如果N为奇数的话,就让第一个数和0组成一对,然后考虑每一对,无论前面的位置移动多少,后面一个点总能移动相同的距离使得两个点对之间的距离保持不变,所以我们就可以将每一对之间的距离拿出来,就变成了了这(N+1)/2个数之间的NIM博弈了,异或即可,很巧妙的一道题。

参考代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=;
int T,n,a[maxn],ans; int main()
{
scanf("%d",&T);
while(T--)////
{
scanf("%d",&n);
for(int i=;i<=n;++i) scanf("%d",&a[i]); sort(a+,a+n+);
ans=; a[]=;
for(int i=n;i>;i-=)
ans^=(a[i]-a[i-]-);
if(ans) puts("Georgia will win");
else puts("Bob will win");
} return ;
}

POJ1704 Georgia and Bob(Nim博弈变形)的更多相关文章

  1. POJ1704 Georgia and Bob (阶梯博弈)

    Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Subm ...

  2. POJ1704 Georgia and Bob Nim游戏

    POJ1704 这道题可以转化为经典的Nim游戏来解决. Nim游戏是这样的 有n堆石子,每堆各有ai个. 两个人轮流在任意石子堆中取至少1个石子,不能再取的输. 解决方法如下, 对N堆石子求异或 为 ...

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

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

  4. POJ1704 Georgia and Bob 题解

    阶梯博弈的变形.不知道的话还是一道挺神的题. 将所有的棋子两两绑在一起,对于奇数个棋子的情况,将其与起点看作一组.于是便可以将一组棋子的中间格子数看作一推石子.对靠右棋子的操作是取石子,而对左棋子的操 ...

  5. POJ1704 Georgia and Bob

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9771   Accepted: 3220 Description Georg ...

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

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

  7. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  8. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

  9. POJ Georgia and Bob-----阶梯博弈变形。

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

随机推荐

  1. mysql group by使用方法注意

    mysql group by使用方法注意 group by 后面只用能用having 不能加 where等域名

  2. SAP HCM 评估路径

    一.评估路径的配置方法: 1)IMG菜单路径:人事管理-〉组织管理-〉基本设置-〉维护评估路径:   2)首先定义评估路径的名称和描述,客户自定义的评估路径的名称编码可以采用字母数字编码,最大长度是八 ...

  3. AI的真实感

    目录 1.让AI"不完美"--估算和假设 2 AI感知 全能感知 特定感觉无知 3 AI的个性 4 AI的预判 5 AI的智能等级 ​ AI的真实感一直是游戏AI程序员追求的目标, ...

  4. 美团店铺数据抓取 token解析与生成

    美团.点评网的token都是用一套加密算法,实际上就是个gzip压缩算法.加密了2次,第一次是加密了个sign值,然后把sign值带进去参数中进行第二次加密,最后得出token 分析请求 打开上海美食 ...

  5. 深入理解计算机系统 第八章 异常控制流 part2

    关于进程,需要关注其提供给应用程序的两个关键抽象: 1.一个独立的逻辑控制流,它提供一个假象,好像我们的程序独占地使用处理器 2.一个私有的地址空间,它提供一个假象,好像我们的程序独占地使用内存系统 ...

  6. 一次shardingjdbc踩坑引起的胡思乱想

    项目里面的一个分表用到了sharding-jdbc 当时纠结过是用mycat还是用sharding-jdbc的, 但是最终还是用了sharding-jdbc, 原因如下: 1. mycat比较重, 相 ...

  7. 力扣(LeetCode)三个数的最大乘积 个人题解

    给定一个整型数组,在数组中找出由三个数组成的最大乘积,并输出这个乘积. 示例 1: 输入: [1,2,3] 输出: 6 示例 2: 输入: [1,2,3,4] 输出: 24 注意: 给定的整型数组长度 ...

  8. 024.掌握Pod-部署MongoDB

    一 前期准备 1.1 前置条件 集群部署:Kubernetes集群部署参考003--019. glusterfs-Kubernetes部署:参考<附010.Kubernetes永久存储之Glus ...

  9. mysql锁简谈

    1.mysql锁, 作用:解决因资源共享而造成的并发问题. 实例:买最好一件衣服X A: X 买: X加锁----->试衣服……下单……付款……打包….------>X解锁 B: X 买: ...

  10. [ch02-03] 梯度下降

    系列博客,原文在笔者所维护的github上:https://aka.ms/beginnerAI, 点击star加星不要吝啬,星越多笔者越努力. 2.3 梯度下降 2.3.1 从自然现象中理解梯度下降 ...