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先走.每个人每一次可以把一枚棋子向左移动任意个格子,但是不能超越其他 ...
随机推荐
- Vue 自定义VueRouter-简版
主要是思路,自己定义组件的时候可以借鉴 Vue-router的 类图 name options: ==> 记录构造函数中传入的对象,在 new VueRouter的时候传了一个对象( route ...
- 关于vector的erase删除操作的两种不同方法,在linux与visual studio的实现讨论
关于vector的erase删除操作的两种不同方法,在linux与visual studio的实现讨论 1.前言: 最近在做某一个题时,用到了vector的删除操作,利用的是erase()函数删除符合 ...
- 源代码管理工具 ——Git的介绍与简要教程
一.Github与Git (一)简介 GitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名GitHub. GitHub于2008年4月10日正式上线 ...
- 程序流程结构——if语句
c语言支持最基本的三种运行结构: 顺序结构:程序按顺序执行,不发生跳转 选择结构:根据是否满足条件 ,有选择的执行相应功能 循环结构:依据条件是否满足,循环多次执行某段代码 #define _CRT_ ...
- unity探索者之protobuf的序列化和反序列化导致unity崩溃的问题研究
版权声明:本文为原创文章,转载请声明http://www.cnblogs.com/unityExplorer/p/7574569.html 这两天博主在接微信支付SDK的时候碰到一个非常恶心又诡异的问 ...
- 使用openpyxl创建excel,设置不显示网格线
最近在学openpyxl,想设置excel不显示网格线,试了好多种方法都不行,最后发现可以通过修改views文件来实现. 文件路径:虚拟目录\Lib\site-packages\openpyxl\wo ...
- Ubuntu下载连接(阿里云镜像)
ubuntu 14.04: http://mirrors.aliyun.com/ubuntu-releases/14.04/ ubuntu 16.04: http://mirrors.aliyun.c ...
- 算法-图(4)用边表示活动的网络(AOE网络)Activity On Edge Network
有向边表示活动,权值表示活动的持续时间,顶点表示事件. 只有一个开始点和完成点,称为源点.汇点,完成工程时间取决于从源点到汇点的最长路径长度,即在这条路径(关键路径)上所有活动的持续时间之和.关键路径 ...
- Java面试题(JVM篇)
JVM 194.说一下 jvm 的主要组成部分?及其作用? 类加载器(ClassLoader) 运行时数据区(Runtime Data Area) 执行引擎(Execution Engine) 本地库 ...
- 性能提升40%: 腾讯 TKE 用 eBPF 绕过 conntrack 优化 K8s Service
Kubernetes Service 用于实现集群中业务之间的互相调用和负载均衡,目前社区的实现主要有userspace,iptables和IPVS三种模式.IPVS模式的性能最好,但依然有优化的空间 ...