POJ1704 Georgia and Bob (阶梯博弈)
| Time Limit: 1000MS | Memory Limit: 10000KB | 64bit IO Format: %I64d & %I64u |
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
Output
Sample Input
2
3
1 2 3
8
1 5 6 7 9 12 14 17
Sample Output
Bob will win
Georgia will win
首先认识一下什么是阶梯博弈。注意这个网址中所说的“2^3^4=5 不为零所以先手必败”是错的
异或不为0应该是先手必胜,说反了。
http://blog.csdn.net/kk303/article/details/6692506
思路:
1 5 6 7 9 12 14 17
第一个棋子不能向左移动了。第二个棋子可以向左移动3个格子。第三个棋子也不能移动了,以此类推,可以得到这样一个数列:
0 3 0 0 1 2 1 2,第n个数字代表第n个棋子可以移动的步数。
考虑一下把第二个棋子向左移动一格的情况,原数列变为:
0 2 1 0 1 2 1 2
这不就是把“第二堆”石子移了一个到右边的“第三堆”石子么?由此可以给出等价的游戏新定义:
给定N堆石子,每堆里面的石子个数都是非负的。每次可以把第i堆中的任意颗石子移动到第i + 1堆中(1 <= i < N),或者第N堆的石子扔掉任意颗。如果某人不能继续操作则判负。
注意最右面的棋子不是一直不动的,因为要保证异或值为0,所以最右面的棋子也要动。
把这个问题看做是每一个石子相对于前一个石子运动。
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
//注意在本题中若循环跑的是1到n 在运算过程中一定不能视a[0]默认为0 新定义的数组a[0]不一定是0
int n,a[],ans=;
cin>>n;
for(int i=;i<n;i++)
cin>>a[i];
sort(a,a+n);
for(int i=n-;i>=;i--)
a[i]=a[i]-a[i-]-;
a[]-=;
for(int i=n-;i>=;i-=)
ans^=a[i];
if(ans)
cout<<"Georgia will win"<<endl;
else
cout<<"Bob will win"<<endl;
}
return ;
}
POJ1704 Georgia and Bob (阶梯博弈)的更多相关文章
- poj 1704 Georgia and Bob(阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9363 Accepted: 3055 D ...
- POJ1704 Georgia and Bob(Nim博弈变形)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14312 Accepted: 4840 ...
- hdu 4315 Climbing the Hill && poj 1704 Georgia and Bob阶梯博弈--尼姆博弈
参考博客 先讲一下Georgia and Bob: 题意: 给你一排球的位置(全部在x轴上操作),你要把他们都移动到0位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...
- POJ1704 Georgia and Bob 博弈论 尼姆博弈 阶梯博弈
http://poj.org/problem?id=1704 我并不知道阶梯博弈是什么玩意儿,但是这道题的所有题解博客都写了这个标签,所以我也写了,百度了一下,大概是一种和这道题类似的能转换为尼姆博弈 ...
- POJ 1704 Georgia and Bob(阶梯Nim博弈)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11357 Accepted: 3749 Description Geor ...
- POJ1704 Georgia and Bob 题解
阶梯博弈的变形.不知道的话还是一道挺神的题. 将所有的棋子两两绑在一起,对于奇数个棋子的情况,将其与起点看作一组.于是便可以将一组棋子的中间格子数看作一推石子.对靠右棋子的操作是取石子,而对左棋子的操 ...
- POJ1704 Georgia and Bob
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9771 Accepted: 3220 Description Georg ...
- [POJ1704]Georgia and Bob 博弈论
从这开始我们来进入做题环节!作为一个较为抽象的知识点,博弈论一定要结合题目才更显魅力.今天,我主要介绍一些经典的题目,重点是去理解模型的转化,sg函数的推理和证明.话不多说,现在开始! Georgia ...
- POJ 1704 Georgia and Bob [阶梯Nim]
题意: 每次可以向左移动一个棋子任意步,不能跨过棋子 很巧妙的转化,把棋子间的空隙看成石子堆 然后裸阶梯Nim #include <iostream> #include <cstdi ...
随机推荐
- 【poj1740】 A New Stone Game
http://poj.org/problem?id=1740 (题目链接) 男人八题之一 题意 对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该 ...
- BZOJ2654 tree
Description 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有need条白色边的生成树. 题目保证有解. Input 第一行V,E,need分别表示点数,边数和需要的白色 ...
- [转] 计算几何模板Orz
#include<math.h> #define MAXN 1000 #define offset 10000 #define eps 1e-8 #define PI acos(-1.0) ...
- IOS基础之(十四) KVO/KVC
资料参考: http://www.cnblogs.com/kenshincui/p/3871178.html http://www.cnblogs.com/stoic/archive/2012/07/ ...
- centos 配置固定ip
centos下网络配置方法(网关.dns.ip地址配置) 来源:互联网 作者:佚名 时间:07-13 00:32:07 [大 中 小] 本文介绍了centos网络配置的方法,centos网络配置主要包 ...
- error MSB4019: 未找到导入的项目“C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets”
error MSB4019: 未找到导入的项目“C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\ ...
- Visual Studio Online Integrations-Sync and migration
原文:http://www.visualstudio.com/zh-cn/explore/vso-integrations-directory-vs
- CNN 美国有线电视新闻网 wapCNN WAP 指无线应用通讯协议 ---- 美国有线电视新闻网 的无线应用
wapCNN wap指无线应用通讯协议 CNN美国有线电视新闻网 固, wapCNN 美国有线电视新闻网的无线应用 -------------------------------------- ...
- php中array_flip数组翻转
array_flip() 函数返回一个反转后的数组,如果同一值出现了多次,则最后一个键名将作为它的值,所有其他的键名都将丢失. 如果原数组中的值的数据类型不是字符串或整数,函数将报错. Return ...
- [转]优化wp_head()
经过对head的优化,我的博客访问速度也快了好多,在此过程中也了解到wp_head()模板函数的作用,可以再次优化,特此记录. 步骤:加入到function.phpremove_action(‘wp_ ...