Georgia and Bob POJ - 1704 阶梯Nim
$ \color{#0066ff}{ 题目描述 }$
Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, ..., and place N chessmen on different grids, as shown in the following figure for example: 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?
\(\color{#0066ff}{输入格式}\)
The 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.
\(\color{#0066ff}{输出格式}\)
For each test case, prints a single line, "Georgia will win", if Georgiawill win the game; "Bob will win", if Bob will win the game; otherwise 'Not sure'.
\(\color{#0066ff}{输入样例}\)
2
3
1 2 3
8
1 5 6 7 9 12 14 17
\(\color{#0066ff}{输出样例}\)
Bob will win
Georgia will win
\(\color{#0066ff}{数据范围与提示}\)
none
\(\color{#0066ff}{题解}\)
移动一个棋子,与左边的距离减小,与右边的距离增大
可以抽象成几堆石子,从一堆拿到另一堆,这就是阶梯NIM了
#include <cctype>
#include <cstdio>
#include <algorithm>
#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
const int maxn = 2050;
int a[maxn], b[maxn];
int main() {
for(int T = in(); T --> 0;) {
int n = in();
for(int i = 1; i <= n; i++) a[i] = in();
std::sort(a + 1, a + n + 1);
int ans = 0;
for(int i = n; i >= 1; i -= 2)
ans = ans ^ (a[i] - a[i - 1] - 1) ;
puts(!ans? "Bob will win" : "Georgia will win");
}
return 0;
}
Georgia and Bob POJ - 1704 阶梯Nim的更多相关文章
- Georgia and Bob(POJ 1704)
原题如下: Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12712 Accepted: ...
- POJ 1704 Staircase Nim 阶梯博弈
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ...
- poj 1704 阶梯博弈
转自http://blog.sina.com.cn/s/blog_63e4cf2f0100tq4i.html 今天在POJ做了一道博弈题..进而了解到了阶梯博弈...下面阐述一下我对于阶梯博弈的理解. ...
- poj 1704 Georgia and Bob(阶梯博弈)
Georgia and Bob Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9363 Accepted: 3055 D ...
- POJ 1704 Georgia and Bob [阶梯Nim]
题意: 每次可以向左移动一个棋子任意步,不能跨过棋子 很巧妙的转化,把棋子间的空隙看成石子堆 然后裸阶梯Nim #include <iostream> #include <cstdi ...
- POJ 1704 Georgia and Bob(阶梯Nim博弈)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11357 Accepted: 3749 Description Geor ...
- POJ 1704 Georgia and Bob(阶梯博弈+证明)
POJ 1704 题目链接 关于阶梯博弈有如下定理: 将所有奇数阶梯看作n堆石头,做Nim,将石头从奇数堆移动到偶数堆看作取走石头,同样地,异或值不为0(利己态)时,先手必胜. 定理证明看此博:htt ...
- 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(Staircase Nim)
Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...
随机推荐
- HTTP 2 的新特性你 get 了吗?
导语 HTTP/2 的主要设计思想应该都是源自 Google的 SPDY 协议,是互联网工程任务组 ( IETF ) 对谷歌提出的 SPDY 协议进行标准化才有了现在的 HTTP/2 .下面我们直奔主 ...
- 手机自带输入法emoji表情的输入,提交及显示——前端解决方案
体验更优排版请移步原文:http://blog.kwin.wang/programming/emoji-transform-commit.html 之前就遇到过需要前端支持用户输入并提交emoji表情 ...
- PHP 取网页变量
$_POST["test"]; $_GET["test"];isset(); if(isset($_GET["yyuid"]))
- CSS JQuyer 元素选择
$(this) 当前 HTML 元素 $("p") 所有 <p> 元素 $("p.intro") 所有 class="intro" ...
- 最长上升子序列(LIS)
最长递增子序列,Longest Increasing Subsequence 下面我们简记为 LIS.排序+LCS算法 以及 DP算法就忽略了,这两个太容易理解了. 假设存在一个序列d[1..9] = ...
- 各大IT/IC公司offer比较
1:本人西电通院2013届毕业硕士,根据今年找工作的情况以及身边同学的汇总,总结各大公司的待遇如下,吐血奉献给各位学弟学妹,公司比较全,你想去的公司不在这里面,基本上是无名小公司了:但无名小公司有时也 ...
- 介绍个好点的,JAVA技术群
java技术交流,意义是以QQ群为媒介,添加一些有多年工作经验和技术的人群,为有问题的人群解答在工作中遇到的各种问题为思想,java技术交流群号161571685,创建时间为2010年,走过将近5年的 ...
- WordPress 4.1去掉侧边栏“功能”小工具中WordPress.Org
打开wp-includes/default-widgets.php,注释掉第398到第403行 echo apply_filters( 'widget_meta_poweredby', sprintf ...
- solr开发之基本操作
package zr.com.util; import java.io.IOException; import java.util.List; import java.util.Map; import ...
- 【摘自大型网站技术架构书】负载均衡时session如何共享
由于负载均衡服务器可能会将请求分发到集群任何一台服务器上,所以保证每次请求能够获得正确的session比单机时复杂. 集群环境下,session管理的主要几种手段 1.session复制 sessio ...