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 ...
随机推荐
- 【bzoj1486】 HNOI2009—最小圈
http://www.lydsy.com/JudgeOnline/problem.php?id=1486 (题目链接) 题意 给出一张有向图,规定一个数值u表示图中一个环的权值/环中节点个数.求最小的 ...
- SQLServer用sql语句怎么返回一个月所有的天数
可用如下sql语句: select convert(varchar(10),dateadd(DAY,t2.number,t1.day),120) day from (select '2015-07'+ ...
- UVA 1626 Brackets sequence(括号匹配 + 区间DP)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/E 题意:添加最少的括号,让每个括号都能匹配并输出 分析:dp ...
- json对象和json字符串有啥区别啊
json对象可以通过javascript存取属性!json对象装成json字符串经常用于前后台传输数据! 如果你在前台使用,那么Json对象可以通过xx.name来调用,如果是字符串,那么就是字符串了 ...
- Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/dyld_sim is not owned by root.
sudo chown -R root /Applications/Xcode6.1.1.app/ 这里把这个 /Applications/Xcode6.1.1.app/替换成你xocde据在的位置
- 新浪微博客户端(3)-封装UIBarButtonItem
单独给NavigationBar上的两个NavigationItem设置图片显得比较麻烦,下面对创建单个UIBarButtonItem的过程进行封装. UIBarButtonItem+Extensio ...
- [Angularjs]ng-switch用法
用法描述 ng-switch根据表达式的值显示或这隐藏对应部分.类似c#或者其他预览里面的switch用法.可以慢慢体会. 说道ng-switch就要说到子元素该怎么根据当前值进行变化.子元素可以通过 ...
- Gulp, 比Grunt更好用的前端构建工具
Gulp, 比Grunt更好用的前端构建工具 本文主要从两个方面介绍Gulp:一,Gulp相对于Grunt的优势: 二,Gulp的安装和使用流程 Gulp相对于Grunt的优势 gulp.js 的作者 ...
- javascript trigger触发事件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- cocos基础教程(5)数据结构介绍之cocos2d::Map<K,V>
1.概述 cocos2d::Map<K,V> 是一个内部使用了 std::unordered_map的关联容器模版. std::unordered_map 是一个存储了由key-value ...