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).两人每次可以将任意一个可移动的棋子向左移动一个单位. ...
随机推荐
- sql server split函数
--创建分割函数CREATE FUNCTION dbo.Split(@String varchar(8000),@Delimiter char(1))returns @temptable TABLE ...
- Sql Server 2008 还原数据库 3154错误
sqlserver2008还原数据库时出现了3154错误,具体错误信息如下: 错误信息 The backup set holds a backup of a database other than t ...
- 枚举N行N列的自然数列
数据库环境:SQL SERVER 2005 现有一个需求,要枚举1-50个自然数,分10行5列展示.如图,
- ios 用LLDB查看模拟器文件路径以及一些常用的命令
我看网络上有好多有关lldb调试命令的介绍,我都看了一遍,都没有这个方法,所以我在这里补充出来,帮助需要的人. 另外附上一些 实用LLDB命令 我们可以使用e命令定义变量 (lldb) e NSStr ...
- C++的显示转换
利用显示转换使得我们可以很容易发现它们,因为通过名字就能找到: static_cast 用于“良性”和“适度良性”转换,包括不用强制转换 const_cast 对“const”和“volatil ...
- YZOI Easy Round 2_化简(simplify.c/cpp/pas)
Description 给定一个多项式,输出其化简后的结果. Input 一个字符串,只含有关于字母x 的多项式,不含括号与分式,没有多余的空格. Output 一个字符串,化简后的多项式,按照次数从 ...
- js如何获取一个月的天数 data javascript
js如何获取一个月的天数 function days(year,month){ var dayCount; now = new Date(year,month, 0); dayCount = now. ...
- OpenCV例程实现人脸检测
前段时间看的OpenCV,其实有很多的例子程序,参考代码值得我们学习,对图像特征提取三大法宝:HOG特征,LBP特征,Haar特征有一定了解后. 对本文中的例子程序刚开始没有调通,今晚上调通了,试了试 ...
- mysql备份sql,脚本
MySQL 安装位置:/usr/local/mysq 论坛数据库名称为:bbs MySQL root 密码:123456 数据库备份目的地:/var/db_backup/ #! /bin/bash / ...
- 十进制和n进制的转换(10进制转换为36进制)
答案如下: void Convert() { map<int ,string> maps; maps[0]="0"; maps[1]="1"; ma ...