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先走.每个人每一次可以把一枚棋子向左移动任意个格子,但是不能超越其他 ...
随机推荐
- C#LeetCode刷题之#705-设计哈希集合(Design HashSet)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4114 访问. 不使用任何内建的哈希表库设计一个哈希集合 具体地说 ...
- go微服务系列(三) - 服务调用(http)
1. 关于服务调用 2. 基本方式调用服务 3. 服务调用正确姿势(初步) 3.1 服务端代码 3.2 客户端调用(重要) 1. 关于服务调用 这里的服务调用,我们调用的可以是http api也可以是 ...
- 用python爬取B站在线用户人数
最近在自学Python爬虫,所以想练一下手,用python来爬取B站在线人数,应该可以拿来小小分析一下 设计思路 首先查看网页源代码,找到相应的html,然后利用各种工具(BeautifulSoup或 ...
- hook框架-frida使用-APP在模拟器无法打开,用钩子去除限制
app拿soul为例子 一.环境配置 #模拟器的frida服务为86 #frida-server-12.9.8-android-x86 adb push frida-server-12.9.8-and ...
- Promise 解析
Promise 由于js的语言特性(用户交互)和工作环境(浏览器脚本),决定了它是单线程工作,所以两段脚本不能同时运行,但为了实现功能,所以人们使用了事件和回调来初步解决这个问题,例如(addEven ...
- dpkg:处理 xxx (--configure)时出错解决办法
1.$ sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old //现将info文件夹更名2.$ sudo mkdir /var/lib/dpkg/info ...
- 归并排序-Python实现
归并排序(MergeSort) 归并排序(英语:Merge sort,或mergesort),是创建在归并操作上的一种有效的排序算法,效率为 O(n\log n)(大O符号).1945年由约翰·冯·诺 ...
- git提交限制后提交出错的暴力解决 (使用小乌龟)
1.右键-> TortoiseGit-> 显示日志 2.右键->重置到哪个版本 3. 重新修改提交信息提交
- Jmeter+Ant+jenkins实现api自动化测试的持续集成
0基础上手教程 @jmeter的使用 jmeter是一个基于java语言编写的开源测试工具,广泛应用于接口测试,性能测试,自动化测试. 接口自动化的编写教程,将于后续分享. 问题一:为什么用ant,而 ...
- ent orm笔记2---schema使用(上)
在上一篇关于快速使用ent orm的笔记中,我们再最开始使用entc init User 创建schema,在ent orm 中的schema 其实就是数据库模型,在schema中我们可以通过Fiel ...