POJ1704 Georgia and Bob
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 9771 | Accepted: 3220 |
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
Source
博弈 脑洞题
操作时,棋子可以向前移动某范围内的任意距离←联想到nim问题←联想到sg函数
起初的想法是:将每个间隔长度看做nim游戏中的一堆石子长度,求所有间隔长度的异或和,若异或和为0,后手必胜。
果断WA掉
看到别人的解法是相邻棋子两两配对,每对之间的间隔当做nim石子。
似乎很有道理。如果每个间隔都算的话,减小一个间隔就会增加另一个间隔,而如果两两配对的话,假设a在b前面,a走x格,b也可以多走x格使得状态不变。
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int T,n;
int a[mxn],cnt=;
int main(){
int i,j,x;
T=read();
while(T--){
n=read();
int res=;
a[]=;
for(i=;i<=n;i++)a[i]=read();
if(n&)a[++n]=;
sort(a+,a+n+);
for(i=;i<=n;i+=){
res^=(a[i+]-a[i]-);
}
if(!res)printf("Bob will win\n");
else printf("Georgia will win\n");
}
return ;
}
POJ1704 Georgia and Bob的更多相关文章
- POJ1704 Georgia and Bob (阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u Subm ...
- [POJ1704]Georgia and Bob 博弈论
从这开始我们来进入做题环节!作为一个较为抽象的知识点,博弈论一定要结合题目才更显魅力.今天,我主要介绍一些经典的题目,重点是去理解模型的转化,sg函数的推理和证明.话不多说,现在开始! Georgia ...
- POJ1704 Georgia and Bob(Nim博弈变形)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14312 Accepted: 4840 ...
- POJ1704 Georgia and Bob Nim游戏
POJ1704 这道题可以转化为经典的Nim游戏来解决. Nim游戏是这样的 有n堆石子,每堆各有ai个. 两个人轮流在任意石子堆中取至少1个石子,不能再取的输. 解决方法如下, 对N堆石子求异或 为 ...
- POJ1704 Georgia and Bob 博弈论 尼姆博弈 阶梯博弈
http://poj.org/problem?id=1704 我并不知道阶梯博弈是什么玩意儿,但是这道题的所有题解博客都写了这个标签,所以我也写了,百度了一下,大概是一种和这道题类似的能转换为尼姆博弈 ...
- POJ1704 Georgia and Bob 题解
阶梯博弈的变形.不知道的话还是一道挺神的题. 将所有的棋子两两绑在一起,对于奇数个棋子的情况,将其与起点看作一组.于是便可以将一组棋子的中间格子数看作一推石子.对靠右棋子的操作是取石子,而对左棋子的操 ...
- 【POJ1704】Georgia and Bob(博弈论)
[POJ1704]Georgia and Bob(博弈论) 题面 POJ Vjudge 题解 这种一列格子中移动棋子的问题一般可以看做成一个阶梯博弈. 将一个棋子向左移动时,它和前面棋子的距离变小,和 ...
- [poj1704]Georgia and Bob_博弈论
Georgia and Bob poj-1704 题目大意:题目链接 注释:略. 想法:我们从最后一个球开始,每两个凑成一对.如果有奇数个球,那就让第一个球和开始位置作为一对. 那么如果对手移动的是一 ...
- [原博客] POJ 1704 Georgia and Bob
题目链接题意:如图,Georgia和Bob在玩游戏.一个无限长的棋盘上有N个旗子,第i个棋子的位置可以用Pi表示.现在Georgia先走.每个人每一次可以把一枚棋子向左移动任意个格子,但是不能超越其他 ...
随机推荐
- elasticsearch高级配置二----线程池设置
一个Elasticsearch节点会有多个线程池,但重要的是下面四个: 索引(index):主要是索引数据和删除数据操作(默认是cached类型) 搜索(search):主要是获取,统计和搜索操作(默 ...
- [deviceone开发]-do_Album的简单示例
一.简介do_Album用来打开手机系统提供的相册,能选择一张或多张图片返回给开发者,通常相册的图片比较大,要经过缩放.有的时候用户也需要把别的地方获取到到图片收藏到系统相册.这个示例简单展示这个组件 ...
- Using View and Data API with Meteor
By Daniel Du I have been studying Meteor these days, and find that Meteor is really a mind-blowing f ...
- IT软件的编程方向 - 进阶者系列 - 学习者系列文章
IT软件经过了这么些年的发展,已经形成了很多的软件公司和开发团队,而且当前编程语言也有很多种,让开发人员能够有很大的选择.现在国际上的开发阵营基本分为ASP.NET.JAVA和PHP三种,但是每种开发 ...
- 信息系统实践手记5-CACHE设计一例
说明:信息系统实践手记系列是系笔者在平时研发中先后遇到的大小的问题,也许朴实和细微,但往往却是经常遇到的问题.笔者对其中比较典型的加以收集,描述,归纳和分享. 摘要:此文描述了笔者接触过的部分信息系统 ...
- paramiko 的使用
paramiko模块,该模块机遇SSH用于连接远程服务器并执行相关操作 SSHClient 用于远程连接机器执行基本命令,也可以执行shell脚本 基于用户名密码连接: def ssh_connect ...
- Echarts在JavaWeb中与后台的交互实现
本Web系统后台框架是:Spring+SpringMVC+Mybatis+Shiro+Maven.完整系统搭建的配置过程见上一篇文章:基于Spring+SpringMVC+Mybatis的Web系统搭 ...
- 文本处理三剑客之sed命令
第十八章.文本处理三剑客之sed命令 目录 sed介绍 sed命令常用选项 sed常用编辑命令 sed使用示例 sed高级语法 18.1.sed简介 sed全名stream editor,流编辑器,s ...
- Spark作业调度阶段分析
Spark作为分布式的大数据处理框架必然或涉及到大量的作业调度,如果能够理解Spark中的调度对我们编写或优化Spark程序都是有很大帮助的: 在Spark中存在转换操作(Transformation ...
- html框架练习
<html><frameset rows="50,*" ><frame name="main" src="/examp ...