• 原题如下:

    Georgia and Bob
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 12712   Accepted: 4262

    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
  • 题解:如果将棋子两两成对当成整体来考虑,就可以把这个游戏转为Nim游戏。如果棋子个数为偶数,把棋子从前往后两两组成一对,可以将每对棋子看成Nim中的一堆石子,石子的个数等于两个棋子之间的间隔。将右边的棋子向左移就相当于从Nim的石子堆中取走石子,将左边的棋子向左移,石子的数量增加了,这和Nim不同,但即便对手增加了石子的数量,只要将所加部分减回去就回到了原来的状态。因此,该游戏的胜负状态和所转移成的Nim的胜负状态一致。
  • 代码:
     #include<cstdio>
    #include<algorithm> using namespace std; const int MAX_N=;
    int T, N, P[MAX_N]; int main()
    {
    scanf("%d", &T);
    while (T>)
    {
    T--;
    scanf("%d", &N);
    for (int i=; i<N; i++)
    {
    scanf("%d", &P[i]);
    }
    if (N%==) P[N++]=;
    sort(P, P+N);
    int x=;
    for (int i=; i+<N; i+=)
    {
    x ^= (P[i+]-P[i]-);
    }
    if (x==) puts("Bob will win");
    else puts("Georgia will win");
    }
    }

Georgia and Bob(POJ 1704)的更多相关文章

  1. Georgia and Bob POJ - 1704 阶梯Nim

    $ \color{#0066ff}{ 题目描述 }$ Georgia and Bob decide to play a self-invented game. They draw a row of g ...

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

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

  3. 【POJ】【1704】Georgia and Bob

    组合游戏 Nim游戏的一个变形 题解请看金海峰的博客 以下为引用: 分析:我们把棋子按位置升序排列后,从后往前把他们两两绑定成一对.如果总个数是奇数,就把最前面一个和边界(位置为0)绑定. 在同一对棋 ...

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

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

  5. 【POJ】1704 Georgia and Bob(Staircase Nim)

    Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...

  6. 【poj 1704】Georgia and Bob

    Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9776 Accepted: 3222 Description Georgia a ...

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

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

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

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11357   Accepted: 3749 Description Geor ...

  9. [原博客] POJ 1704 Georgia and Bob

    题目链接题意:如图,Georgia和Bob在玩游戏.一个无限长的棋盘上有N个旗子,第i个棋子的位置可以用Pi表示.现在Georgia先走.每个人每一次可以把一枚棋子向左移动任意个格子,但是不能超越其他 ...

随机推荐

  1. C#LeetCode刷题之#136-只出现一次的数字(Single Number)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4046 访问. 给定一个非空整数数组,除了某个元素只出现一次以外, ...

  2. (数据科学学习手札93)利用geopandas与PostGIS进行交互

    本文完整代码及数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 PostGIS作为postgresql针对 ...

  3. JavaFX桌面应用-视频转码工具(支持爱奇艺qsv转mp4)

    最近由于需要将在爱奇艺下载的视频(qsv)转化了mp4,用JavaFX开发一个视频转码工具,算是JavaFX开发的第一个应用吧. 支持qsv转码mp4,理论上支持各种格式,仅测试了flv,qsv格式. ...

  4. ExcelWeb脚本助手,自定义脚本,批量操作Excel与网页

    ExcelWeb脚本助手,是一款可以自定义脚本操控Excel和浏览器的工具.提供了简单实用的Excel与Browser的API调用,通过自建脚本或自建项目,随意定制. 可以非常方便的根据Excel中的 ...

  5. html表格、表单

    知识点一:表格 1.表格标签  table 2.表格的组成  行 tr  单元格  td 3.建立表格步骤 1.建立表格, 2.判断行数和列数 3.用行去包含单元格 4.在每个单元格中去添加内容 4. ...

  6. Ubuntu 18.04 安装 docker, 设置阿里云加速

    1.卸载旧的 docker 环境 sudo apt-get remove docker docker-engine docker.io containerd runc 2.设置仓库 更新索引 sudo ...

  7. Wireshark中的Checksum: 0x90c5 [validation disabled]问题

    Wireshark中的Checksum: 0x90c5 [validation disabled]问题 废话不多说先上问题图: 这是我在做关于DNS协议PPT的时候出现的协议树第五项展开结果,可以发现 ...

  8. Hadoop的源码编译

    目录 正文 1.准备阶段 使用root登录Centos,并且要求能够正常连接网络.配置清单如下: (1)hadoop-2.7.2-src.tar.gz (2)jdk-8u144-linux-x64.t ...

  9. Linux三剑客老三---grep

    1.Linux三剑客老三 过滤需要的内容,例子:grep -v oldboy hello.txt grep一般常用参数: -a:在二进制文件中,以文本文件的方式搜索数据. -c:计算找到"搜 ...

  10. 《Java从入门到失业》第三章:基础语法及基本程序结构(四):基本数据类型(字符编码和char型)

    3.6.4字符编码 咦?怎么好像有东西乱入了?不是讲基本数据类型么?哈哈,因为还剩下最后一个char型了,因为char型会牵涉到Unicode编码相关,因此我决定先科普一下字符集编码. 我儿子现在上小 ...