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先走.每个人每一次可以把一枚棋子向左移动任意个格子,但是不能超越其他 ...
随机推荐
- Android开发学习进程0.18 SharePreference的使用 AIDL
SharePreference SharePreference是一种持久化存储手段,使用场景很多,如第一次打开时加载的用户协议等.适合小数据单进程的应用.将数据以键值对的形式存储在XML中. 使用方式 ...
- ElementUi——el-select下拉框
<el-select v-model="ruleForm.status" placeholder="请选择状态" @change="styleC ...
- jQuery的小测试
1.在div元素中,包含了一个<span>元素,通过has选择器获取<div>元素中的<span>元素的语法是? $('div:has(span)'); 2.在&l ...
- 浅谈:C#中的非泛型集合
1.首先:ArrayList:非泛型集合 List:泛型集合 集合跟数组比较我们更容易理解.数组:1,长度固定2,数据类型预先声明 集合:1,长度可变2,数据类型预先声明的为泛型集合,数据类型不限定为 ...
- 轻音少女K-on闹钟,时钟,日历,整点报时
在网上找了很久才找到这个东西, 所以分享出了,方便大家下载 链接: https://pan.baidu.com/s/11wB57F2Td1FPp9RBmTvg 密码: 2xt5
- day3 基本语句
代码缩进为一个tab键 就是四个空格 断点 在代码首行前空白处,双击 然后点右上角臭虫 然后点下面箭头朝下的 1.if 语句 if 判断条件: ...
- Linux基础 Day2
Linux-Day2 1.文件目录结构 文件和目录被组织成一颗倒置的树的结构 文件系统从根开始,"/" 文件名称严格区分大小写 隐藏文件以"."开头 路径的分隔 ...
- Sqlalchemy 事件监听与初始化
sqlalchemy不仅仅能自动创建数据库,更提供了其他更强大的功能,今天要介绍的就是sqlalchemy中的事件监听,并将其应用到数据库的初始化中. 需求:当插入设置password字段时,自动加密 ...
- CentOS 7环境下大量创建账号的方法
1 一些账号相关的检查工具 1.1 pwck命令 pwck 这个指令在检查 /etc/passwd 这个账号配置文件内的信息,与实际的家目录是否存在等信息,还可以比对 /etc/passwd /etc ...
- 医疗seo常用的图标工具
http://www.wocaoseo.com/thread-304-1-1.html 下面是一些医疗seo常用的一些图表工具,这些都是些最简单的工具,主要放置这里以防止以后有作用. 1,医疗的常用搜 ...