【poj 1704】Georgia and Bob
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 9776 Accepted: 3222
Description
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?
Input
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.
Output
For each test case, prints a single line, “Georgia will win”, if Georgia will win the game; “Bob will win”, if Bob will win the game; otherwise ‘Not sure’.
Sample Input
2
3
1 2 3
8
1 5 6 7 9 12 14 17
Sample Output
Bob will win
Georgia will win
【题目链接】:http://poj.org/problem?id=1704
【题解】
这题是阶梯博弈;
可以这样;
比如
第2个样例
8
1 5 6 7 9 12 14 17
则这样两两组合
(1 5) (6 7) (9 12) (14 17)
1和5之间有3个位置可供5往左移动
6和7之间7是不能移动了的
9和12之间有两个位置供12左移
14和17之间有两个位置供17左移
则对
3 0 2 2做nim博弈;
因为3^0^2^2不为0,所以先手赢;
为什么呢?
可以这样理解,
先手减去3,0,2,2中的某一个数字;
可以理解为把那一个组合右边的棋子左移了x格,x为这个数字的减少量
比如吧最后一个2减去1;
->3 0 2 1
就对应了棋盘上的棋子
1 5 6 7 9 12 14 16
如果后者不是移动组合中的右边那个棋子;
而是左边的那个棋子;
比如把14左移到了13;
那么我们可以把16也左移1位到15
那么棋子变成
1 5 6 7 9 12 13 15
对方面临的状态就还是不变依然为
->3 0 2 1
如果对方不移动组合中右边的棋子,那么就不可能改变状态;(我们总能变回来);
那么如果一开始的3,0,2,1做NIM游戏我们是赢的,那么我们就肯定能赢;
相反,如果我们肯定会输,那么对手也能用这样的策略让我们保持输的状态;
显然如果这4个数字全都变成0了;
(这一瞬间,接下来要面临4个数字都是0且要操作的人肯定会输);
(因为接下来只能操作每个组合中的左边的棋子了,对方怎么操作,你只要跟
把右边那个棋子始终紧挨着它,最后对方就没棋子可以走了!);
知道这一点后;
再对奇数个棋子的情况进行考虑
比如
3
3 8 16
则在3前面加个0
0 3 6 16
->(0 3) (6 16)
->2 9
对2和9做NIM博弈就好;
这里的分析和上面是一样的;
最终你都能“逼”对方对组合中的右边的棋子进行操作;
(也即减少尼姆博奕中各个堆中某个堆的石子个数);
数据没说从小到大排序:(
【完整代码】
//#include <bits/stdc++.h> poj不支持这个
#include <cstdio>
#include <algorithm>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int MAXN = 1e3+10;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
int a[MAXN];
int main()
{
//freopen("F:\\rush.txt","r",stdin);
int T;
rei(T);
while (T--)
{
int n,ju,temp=0;
rei(n);
ju = n&1;
rep1(i,1,n)
rei(a[i]);
sort(a+1,a+1+n);
rep1(i,1,n)
if ((i&1)==ju)
temp ^= a[i]-a[i-1]-1;
if (temp!=0)
puts("Georgia will win");
else
puts("Bob will win");
}
return 0;
}
【poj 1704】Georgia and Bob的更多相关文章
- 【POJ 1704】 Georgia and Bob
[题目链接] http://poj.org/problem?id=1704 [算法] 阶梯博弈 [代码] #include <algorithm> #include <bitset& ...
- 【POJ】【1704】Georgia and Bob
组合游戏 Nim游戏的一个变形 题解请看金海峰的博客 以下为引用: 分析:我们把棋子按位置升序排列后,从后往前把他们两两绑定成一对.如果总个数是奇数,就把最前面一个和边界(位置为0)绑定. 在同一对棋 ...
- 【POJ1704】Georgia and Bob(博弈论)
[POJ1704]Georgia and Bob(博弈论) 题面 POJ Vjudge 题解 这种一列格子中移动棋子的问题一般可以看做成一个阶梯博弈. 将一个棋子向左移动时,它和前面棋子的距离变小,和 ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
随机推荐
- Spider_selenium
json模块 什么是json? javascript中的对象和数组 对象:{key:value}取值:对象名.key 数组:[...,...]取值:数组[索引值] 作用 json格式的字符串和Pyth ...
- oracle数据库spfile
http://blog.chinaunix.net/uid-8996530-id-3195808.html http://www.cnblogs.com/HondaHsu/p/4885318.html ...
- 洛谷 P1636 Einstein学画画
P1636 Einstein学画画 题目描述 Einstein学起了画画, 此人比较懒--,他希望用最少的笔画画出一张画... 给定一个无向图,包含n 个顶点(编号1~n),m 条边,求最少用多少笔可 ...
- Http请求连接池 - HttpClient 的 PoolingHttpClientConnectionManager
两个主机建立连接的过程是非常复杂的一个过程,涉及到多个数据包的交换,而且也非常耗时间.Http连接须要的三次握手开销非常大,这一开销对于比較小的http消息来说更大.但是假设我们直接使用已经建立好的h ...
- 《鸟哥的Linux私房菜-基础学习篇(第三版)》(四)
第3章 主机规划与磁盘分区 1. Linux与硬件的搭配 首先谈了认识计算机的硬件配置. 然后谈了选择与Linux搭配的主机配置. 在Linuxserver中,内存的重要性 ...
- mIsFunui-判断Funui方法
1.有时候我们根据自己的需要,修改了frameword下的代码,但是,我们又不希望影响第三方,这时候我们就可以在修改处添加一个我们自己的标志位,如,mIsFunui 它是定义在我们自定义的theme里 ...
- ORA-16009 remote archive log destination must be a STANDBY database
ORA-16009错误处理 问题描述: 主备在做Switchover切换时,在切换后的备库报如下错误: Wed Jul 22 04:49:02 2015 Errors in file /u01/app ...
- Valgrind的用法
Valgrind是执行在Linux上一套基于仿真技术的程序调试和分析工具,它包括一个内核──一个软件合成的CPU,和一系列的小工具,每一个工具都能够完毕一项任务──调试.分析,或測试等. Valgri ...
- 分治法(divide & conquer)与动态规划(dynamic programming)应用举例
动态规划三大重要概念:最优子结构,边界,状态转移公式(问题规模降低,如问题由 n 的规模降低为 n−1 或 n−2 及二者之间的关系): 0. 爬台阶 F(n)⇒F(n−1)+F(n−2) F(n−1 ...
- JS学习笔记 - fgm练习 - 多按钮控制同个div属性
总结: 1. 注意body里的结构安排,全部装在大div,避免多次设置不同部分居中. 2. 一排按钮居中:装在大div里,text-align: center; 3. 把相同的部分封装成函数,即 同个 ...