Georgia and Bob(POJ 1704)
- 原题如下:
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 17Sample 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)的更多相关文章
- Georgia and Bob POJ - 1704 阶梯Nim
$ \color{#0066ff}{ 题目描述 }$ Georgia and Bob decide to play a self-invented game. They draw a row of g ...
- poj 1704 Georgia and Bob(阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9363 Accepted: 3055 D ...
- 【POJ】【1704】Georgia and Bob
组合游戏 Nim游戏的一个变形 题解请看金海峰的博客 以下为引用: 分析:我们把棋子按位置升序排列后,从后往前把他们两两绑定成一对.如果总个数是奇数,就把最前面一个和边界(位置为0)绑定. 在同一对棋 ...
- POJ 1704 Georgia and Bob(阶梯博弈+证明)
POJ 1704 题目链接 关于阶梯博弈有如下定理: 将所有奇数阶梯看作n堆石头,做Nim,将石头从奇数堆移动到偶数堆看作取走石头,同样地,异或值不为0(利己态)时,先手必胜. 定理证明看此博:htt ...
- 【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, ...
- 【poj 1704】Georgia and Bob
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9776 Accepted: 3222 Description Georgia a ...
- poj 1704 Georgia and Bob(阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8656 Accepted: 2751 D ...
- POJ 1704 Georgia and Bob(阶梯Nim博弈)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11357 Accepted: 3749 Description Geor ...
- [原博客] POJ 1704 Georgia and Bob
题目链接题意:如图,Georgia和Bob在玩游戏.一个无限长的棋盘上有N个旗子,第i个棋子的位置可以用Pi表示.现在Georgia先走.每个人每一次可以把一枚棋子向左移动任意个格子,但是不能超越其他 ...
随机推荐
- mysql的ATM存取款机系统
##建库 CREATE DATABASE bankDB; ##客户信息表 CREATE TABLE userInfo ( customerID INT PRIMARY KEY AUTO_INCREME ...
- 关于java中jdk的环境变量配置
关于java中jdk的环境变量配置 烦死人,在网上找了很长时间.最终找到了一个方法!现在将其总结帮助后来人. 方法/步骤 1 下载好jdk,并按照提示一步步安装,最后记下jdk所在的安装位置,这里 ...
- noip复习——逆元
逆元,即对给定\(a,p\ (a \perp p)\),求\(x\)使得\(ax \equiv 1 \ (\bmod p)\) 逆元可以看做\(a\)在模\(p\)意义下的\(a^{-1}\).因此, ...
- eric4 中 pyqt .py文件结尾的 代码
if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) ui = MainWindow() ...
- 轻松解除官方对博客后台设置页面3段html代码的限制:iframe alert flagcounter etc.的禁用
今天我发现我的flagcounter不能用了 iframe也不能用了,无奈╮(╯_╰)╭ 第一反应是Ctrl U viewsource看看源码出了什么问题 结果竟然是这样, 因为页首和侧边栏的html ...
- Host 'controller' is not mapped to any cell
问题: Host 'controller' is not mapped to any cell 解决: 执行:nova-manage cell_v2 simple_cell_setup 再次检查:
- Java中枚举的常见用法
在JDK1.5以后引入了一种新的类型,就是枚举(enum).enum是用来声明枚举类型数据,它可以像数组一样存储许多的元素,但是不同于数组的是,它除了数字不能存储以外, 其他类型的如字母.特殊符号.汉 ...
- 第2篇 Scrum 冲刺博客
1.站立会议 照骗 进度 成员 昨日完成任务 今日计划任务 遇到的困难 钟智锋 无 确定客户端和服务器通信的形式 各成员的代码难以统一 庄诗楷 无 编写客户端UI 加入图片总是失败 易德康 无 马,车 ...
- 【转】Windows10删除文件时却提示文件不存在的解决方案
Windows10系统使用一段时间后用户都会定期进行删除清理系统垃圾,减少系统盘的容量占用,但在删除的过程中许多用户都有可能遇到无法删除的情况,如下为删除文件时却提示文件不存在的解决方案. 1.新建一 ...
- you-get 下载B站上的视频
安装you-get pip install you-get 安装好后,我们可以查看一下you-get的参数 you-get -h 视频下载 单个视频下载 CMD下载 you-get -o /data/ ...