【POJ】1704 Georgia and Bob(Staircase Nim)
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
----------------------------------------------------
题意:在一条直线的格子上放有一些棋子,两人可以轮流选择一个棋子向左移动,但不能跨过前面的棋子或到同一个,无法进行操作的人输(即所有棋子都被前后逼死,无法移动)。
分析:可以把两个棋子间的距离看做nim游戏中一堆石子的数量,移动即为取走一些石子,但如果格子上有奇数个棋子,此时无法凑成整堆的石子(即两两棋子算作一堆石子的话,会多出一个棋子),这时把0看做一个棋子即可。注意,题目给的棋子位置不是升序,需要自己排序。
P.s.这种问题也被称作Staircase Nim。
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int t,n,p[];
scanf("%d",&t);
while(t--)
{ int x=;
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&p[i]);
if(n%!=) p[n++]=;
sort(p,p+n);
for(int i=;i<n-;i+=)
{
x^=(p[i+]-p[i]-);//不断异或棋子之间的差值,即nim中的石子数
}
if(x==) printf("Bob will win\n");
else printf("Georgia will win\n");
}
return ;
}
AC了,打卡:【POJ】1704 Georgia and Bob
【POJ】1704 Georgia and Bob(Staircase Nim)的更多相关文章
- 【POJ】1704.Georgia and Bob
题解 感觉挺神奇的 我们把石子从后往前相邻的两个两两配对,这样他们之间的空格就相当于一堆石子 而配对后左边棋子移动,右边棋子也一定可以跟上取 转化成简单的nim游戏,最后只要看转化出的这(N - 1) ...
- poj 1704 Georgia and Bob(阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8656 Accepted: 2751 D ...
- POJ 1704 Georgia and Bob(阶梯博弈)题解
题意:有一个一维棋盘,有格子标号1,2,3,......有n个棋子放在一些格子上,两人博弈,只能将棋子向左移,不能和其他棋子重叠,也不能跨越其他棋子,不能超越边界,不能走的人输 思路:可以用阶梯博弈来 ...
- 【POJ】2348 Euclid's Game(扩欧)
Description Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first pl ...
- 【POJ】 1061 青蛙的约会(扩欧)
青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 119148 Accepted: 25070 Descript ...
- 【POJ】1062 昂贵的聘礼 (最短路)
题目 传送门:QWQ 分析 最短路显然,但不好搞地位等级..... 地位等级不好搞?那么就暴力.. 枚举我们允许的地位等级,跑最短路. 所以$ n^2logn $出100什么鬼啊,很有迷惑性啊 还有4 ...
- 【SPOJ】Longest Common Substring II (后缀自动机)
[SPOJ]Longest Common Substring II (后缀自动机) 题面 Vjudge 题意:求若干个串的最长公共子串 题解 对于某一个串构建\(SAM\) 每个串依次进行匹配 同时记 ...
- 【BZOJ1717】产奶的模式(后缀数组)
[BZOJ1717]产奶的模式(后缀数组) 题面 权限题 hihocoder 洛谷 题解 \(hihocoder\)里面讲的非常好了 这题要求的就是最长可重叠重复K次子串 所谓相同的子串 我们可以理解 ...
- 【BZOJ2154】Crash的数字表格(莫比乌斯反演)
[BZOJ2154]Crash的数字表格(莫比乌斯反演) 题面 BZOJ 简化题意: 给定\(n,m\) 求\[\sum_{i=1}^n\sum_{j=1}^mlcm(i,j)\] 题解 以下的一切都 ...
随机推荐
- Ext.grid.EditorGridPanel联动设置单元格是否可以编辑和背景色
listeners:{ "beforeedit":function(iEventobj){ var col = iEventobj.row;//获取行 var record = i ...
- ScrollView嵌套ListView只显示一行
错误描述 ScrollView嵌套ListView中导致ListView高度计算不正确,只显示一行. 解决方法 重写ListView的onMeasure方法,代码如下. @Override publi ...
- element ui datePicker 设置当前日期之前的日期不可选
pickerOptions0: { disabledDate(time) { return time.getTime() < Date.now() - 8.64e7 } },
- 机器学习实战之 第10章 K-Means(K-均值)聚类算法
第 10 章 K-Means(K-均值)聚类算法 K-Means 算法 聚类是一种无监督的学习, 它将相似的对象归到一个簇中, 将不相似对象归到不同簇中.相似这一概念取决于所选择的相似度计算方法.K- ...
- maven 自我学习笔记
1.常用网站: maven.apache.org http://mvnrepository.com/ 2.命令 mvn -v 查看maven的版本 mvn -compile 在项目的根目录下编译项 ...
- c# HttpWebRequest 模拟HTTP post 传递JSON参数
//HTTP post JSON 参数 private string HttpPost(string Url, Object ticket) { ...
- group by 多字段分组
在平时的开发任务中我们经常会用到MYSQL的GROUP BY分组, 用来获取数据表中以分组字段为依据的统计数据.比如有一个学生选课表,表结构如下: Table: Subject_Selection S ...
- Mac上好用的视频播放器有哪些?
首页发现话题 提问 登录加入知乎 Mac 上好用的视频播放器有哪些? 关注问题写回答 OS X 应用 多媒体播放器(软件) Mac 上好用的视频播放器有哪些? 关注者 2680 被浏览 981770 ...
- Mac环境下mysql初始化密码问题--If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.
个人在Mac上操作数据库,遇到的启动数据库问题的简单记录 1.苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) 2.进 ...
- 4th-结对编程2
0x00 Coding Coding地址/小伙伴的博客地址 合作伙伴:庞伊凡(201421123011).赵娅汀(201421123012) 0x01 题目描述 上一周大家为四则运算程序设计了2-3个 ...