poj 1704 Georgia and Bob(阶梯博弈)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8656 | Accepted: 2751 |
Description

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
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
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
Source
【思路】
阶梯博弈
将棋子之间的间距视作一堆石子,则问题可以转化为一类名为阶梯博弈的东西。
即:
如果对方在奇数位上取硬币,那么我们也类似nim在奇数位上取硬币使SG值回到0;
如果对方在偶数位上取硬币。那么我们就把他刚刚从偶数位上传到奇数位上的硬币数。
原封不动的再传回偶数位。这样就可以保持SG=0;
因此把阶梯问题看作奇数项的Nim游戏。
【代码】
#include<cstdio>
#include<algorithm>
using namespace std; int a[],n; int main() {
int T;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
int ans=,s=;
for(int i=n;i>;i-=)
ans^=a[i]-a[i-]-;
if(ans) puts("Georgia will win");
else puts("Bob will win");
}
return ;
}
poj 1704 Georgia and Bob(阶梯博弈)的更多相关文章
- poj 1704 Georgia and Bob(阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9363 Accepted: 3055 D ...
- hdu 4315 Climbing the Hill && poj 1704 Georgia and Bob阶梯博弈--尼姆博弈
参考博客 先讲一下Georgia and Bob: 题意: 给你一排球的位置(全部在x轴上操作),你要把他们都移动到0位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...
- POJ 1704 Georgia and Bob(阶梯Nim博弈)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11357 Accepted: 3749 Description Geor ...
- POJ 1704 Georgia and Bob【博弈】
题目链接: http://poj.org/problem?id=1704 题意: 给定棋子及其在格子上的坐标,两个人轮流选择一个棋子向左移动,每次至少移动一格,但是不可以碰到其他棋子.无路可走的时候视 ...
- POJ 1704 Georgia and Bob [阶梯Nim]
题意: 每次可以向左移动一个棋子任意步,不能跨过棋子 很巧妙的转化,把棋子间的空隙看成石子堆 然后裸阶梯Nim #include <iostream> #include <cstdi ...
- POJ 1704 Georgia and Bob(阶梯博弈+证明)
POJ 1704 题目链接 关于阶梯博弈有如下定理: 将所有奇数阶梯看作n堆石头,做Nim,将石头从奇数堆移动到偶数堆看作取走石头,同样地,异或值不为0(利己态)时,先手必胜. 定理证明看此博:htt ...
- POJ 1704 Georgia and Bob(阶梯博弈)题解
题意:有一个一维棋盘,有格子标号1,2,3,......有n个棋子放在一些格子上,两人博弈,只能将棋子向左移,不能和其他棋子重叠,也不能跨越其他棋子,不能超越边界,不能走的人输 思路:可以用阶梯博弈来 ...
- POJ1704 Georgia and Bob (阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u Subm ...
- POJ.1704.Georgia and Bob(博弈论 Nim)
题目链接 \(Description\) 一个1~INF的坐标轴上有n个棋子,给定坐标Pi.棋子只能向左走,不能跨越棋子,且不能越界(<1).两人每次可以将任意一个可移动的棋子向左移动一个单位. ...
随机推荐
- [XML] resources的Xml配置文件 (转载)
<?xml version="1.0" encoding="utf-8" ?> <resources> <language> ...
- Java写一个简单学生管理系统
其实作为一名Java的程序猿,无论你是初学也好,大神也罢,学生管理系统一直都是一个非常好的例子,初学者主要是用数组.List等等来写出一个简易的学生管理系统,二.牛逼一点的大神则用数据库+swing来 ...
- ASP.NET程序如何更新发布
ASP.NET程序如何更新发布 一.首先右键项目,点击“发布” 然后,新建名称.类型选择文件,然后点击下一步: 点击发布即可! 二.
- iOS-UI控件精讲之UILabel
UILabel(标签)应该是iOS中最基本的一个控件了,也是使用频率最高的,经常用来展示一段不可编辑的文本. UILabel继承于UIView,下面是一些常用的属性,包含继承于UIView的属性. 1 ...
- 简单的背包问题(入门)HDU2602 HDU2546 HDU1864
动态规划,我一直都不熟悉,因为体量不够,所以今天开始努力地学习学习. 当然背包从01开始,先选择了一个简单的经典的背包HDU2602. Many years ago , in Teddy's home ...
- Angularjs简介
很久没有系统学习一个新技术了,angularjs将会比较系统的讲解这个技术的语法.应用.次类型的博客将会持续更新,博主也是一个初学者,如果有问题欢迎留言讨论. angularjs简介. angular ...
- android关于installLocation
以下内容主要参考自官网的描述. 从Android API-8开始,android允许你将应用程序安装到外部存储空间中去(比方:SD卡),你可以在AndroidManifest.xml中添加androi ...
- WebApi(四)-Post接口请求失败或接受不到参数(解决方法)
post方式只能接受一个参数而且必须用FromBody特性标识,所以当没有使用FromBody特性标识的时候就会请求失败,如有添加添加了那访问接口时候参数应传对象不能是key:val的格式否则会接收到 ...
- Struts2技术内幕-----第七章
1)基于人机交互的请求--响应模式主要由哪三大要素构成? ①沟通协议-----人和机器都能够明白的数据通信格式 ②请求内容-----人通过某种机制向机器发起的数据请求 ③响应内 ...
- 30+最佳Ajax jQuery的自动完成插件的例子
在这篇文章中,我们将介绍35个jQuery AJAX的自动完成提示例子. jQuery 的自动完成功能,使用户快速找到并选择一定的价值.每个人都想要快速和即时搜索输入栏位,因为这个原因,许 流行的搜索 ...