Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

Alice and Bob are playing a game called "Climbing the Hill". The game board consists of cells arranged vertically, as the figure below, while the top cell indicates the top of hill. There are several persons at different cells, and there is one special people, that is, the king. Two persons can't occupy the same cell, except the hilltop.

At one move, the player can choose any person, who is not at the hilltop, to climb up any number of cells. But the person can't jump over another one which is 
above him. Alice and Bob move the persons alternatively, and the player who move the king to the hilltop will win.


Alice always move first. Assume they play optimally. Who will win the game? 

 

Input

There are several test cases. The first line of each test case contains two integers N and k (1 <= N <= 1000, 1 <= k <= N), indicating that there are N persons on the 
hill, and the king is the k-th nearest to the top. N different positive integers followed in the second line, indicating the positions of all persons. (The hilltop is No.0 cell, the cell below is No.1, and so on.) These N integers are ordered increasingly, more than 0 and less than 100000.
 

Output

If Alice can win, output "Alice". If not, output "Bob".
 

Sample Input

3 3
1 2 4
2 1
100 200
 

Sample Output

Bob
Alice

Hint

 The figure illustrates the first test case. The gray cell indicates the hilltop. The circles indicate the persons, while the red one indicates the king. The first player Alice can move the person on cell 1 or cell 4 one step up, but it is not allowed to move the person on cell 2. 

题意:在山上有n个人,每个人编号是1~n,这些位置只能同时被一个人占据,但是山顶可以同时被多个人占据,距离山顶第k近的是King,现在Alice和Bob开始向上
          送人,条件是不能跨越前面最近的人,问在Alice先手,双方最优的条件下谁能把King送到山顶。

题解:这个题是2012多校第二场的题目,也是2011年大连站regional热身赛的题目。

阶梯博弈的变种,可以看做是尼姆博弈。

对于这个题目:当k=1时,Alice必胜;

当k!=1时,两两分组,如果前面只有一个球即n为奇数且k=2时,Alice和Bob都不愿移动前面的球到0,所以此时前面球有hill[1]-1种
                               选择,所以hill[1]--。

对于这个题目,从后向前两两划分成一组,组内相当于奇数阶梯上的石子,组间相当于偶数阶梯上的石子,移动组内的前面石子一定能够通过移动当前组的后面石子相同步数达到平衡态,移动组内后面的石子一定能够通过移动其他组后面石子达到平衡态,如果这么考虑的话这题就是阶梯博弈。

注意本题与poj1704的区别。

poj 1704 是每一个点看成一个堆,因为没山顶,每个点相对于前一个点运动,一共有n堆,只异或奇数堆,是阶梯博弈。

本题是每两个点看成一个堆,n=1和k=2要单独讨论,每两个点相对于山顶运动,注意移动的时候山顶永远都算一个空格,异或所有堆,可以看做是尼姆博弈。

也可以将堆与堆之间看做是偶数步的点,也相当于只异或奇数堆,即阶梯博弈。

这个问题是谁能掌握主动权让对面去面对0的事,与k在组内前后无关。

1.假设n=5,k=2。1, 2,5, 6,10。 三堆是0,2,3。先手必胜。先手走成0,2,2让后手面对必败态,后手可以把局面走成0,0,0。

最后最后后手只能选择把第一个数走到0,先手把2移动到0胜。

2.假设n=5,k=4。1,2,5,6,10。三堆是1,2,3。异或为0先手必败。注意这组数据1是可以走到0的上组数据不可以。

3.假设n=4,k=2。1,3,4,7。两堆是1,2。异或不为0先手必胜。先手走成1,1即可。

注意当第一个数1走到0的时候,第二个数3走到的是2而不是1也不是0,1走到了0,3走到了2,中间距离还是1。

即相对运动不改变该堆的值,一定要注意3走到的是2而不是1也不是0。

#include <iostream>
#include <algorithm>
using namespace std;
void pr(int ans)
{
if(ans)
cout<<"Alice"<<endl;
else
cout<<"Bob"<<endl;
}
int main()
{
int n,k;
while(cin>>n>>k)
{
int a[],ans=;
for(int i=; i<=n; i++)
cin>>a[i];
a[]=;
if(k==)
{
cout<<"Alice"<<endl;
continue;
}
if(k!=) a[]=-; //只有当n为奇数的时候才会涉及到a[0] 因为a[1]单成一堆
//意为正常0到a[1]这个堆就应该是a[1]-1的 但是k不在2的时候a[1]可以移动到0
//比正常的堆多一个位置 所以要-(-1)=+1
for(int i=n; i>=; i-=)
ans=ans^(a[i]-a[i-]-); //下面这两句话并不符合题意,但是加上以后却是AC的
//这两句话是在别的代码中提取出来的 想了一宿
//结果发现有没有下面这两句话都是AC的 个人感觉是数据不严谨导致的
//太坑爹
//if(k==2&&n&1) ans^=(a[1]-2); //已经异或了a[1]-1
//else if(k!=2&&n&1) ans^=(a[1]-1);//已经异或了a[1] pr(ans);
}
return ;
}

HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)的更多相关文章

  1. HDU 4315 Climbing the Hill [阶梯Nim]

    传送门 题意: 和上题基本一样:山顶可以有多人,谁先把king放到山顶谁就胜 并不太明白 #include <iostream> #include <cstdio> #incl ...

  2. hdu 4315 Climbing the Hill && poj 1704 Georgia and Bob阶梯博弈--尼姆博弈

    参考博客 先讲一下Georgia and Bob: 题意: 给你一排球的位置(全部在x轴上操作),你要把他们都移动到0位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...

  3. 简单易懂的博弈论讲解(巴什博弈、尼姆博弈、威佐夫博弈、斐波那契博弈、SG定理)

    博弈论入门: 巴什博弈: 两个顶尖聪明的人在玩游戏,有一堆$n$个石子,每次每个人能取$[1,m]$个石子,不能拿的人输,请问先手与后手谁必败? 我们分类讨论一下这个问题: 当$n\le m$时,这时 ...

  4. hdu 4315 Climbing the Hill(阶梯博弈转nim博弈)

    Climbing the Hill Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. HDU 4315 Climbing the Hill(阶梯博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:由上至下有多个格子,最顶端的是山顶,有多个球,其中有一个球是king,每次可以将球向上移动任意个格子 ...

  6. hdu 4315 Climbing the Hill 博弈论

    题意:有n个人爬山,山顶坐标为0,其他人按升序给出,不同的坐标只能容纳一个人(山顶不限),Alice和Bob轮流选择一个人让他移动任意步,但不能越过前面的人,且不能和前面一个人在相同的位置.现在有一个 ...

  7. hdu 1849 (尼姆博弈)

    http://acm.hdu.edu.cn/showproblem.php? pid=1849 简单的尼姆博弈: 代码例如以下: #include <iostream> #include ...

  8. hdu 1907 (尼姆博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very ...

  9. HDU.1850 being a good boy in spring festival (博弈论 尼姆博弈)

    HDU.1850 Being a Good Boy in Spring Festival (博弈论 尼姆博弈) 题意分析 简单的nim 博弈 博弈论快速入门 代码总览 #include <bit ...

随机推荐

  1. HDU-1754I Hate It 线段树区间最值

    这道题比较基本,就是用线段树维护区间最值,可以算是模板吧-.. I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768 ...

  2. codevs2606 约数和问题

    题目描述 Description Smart最近沉迷于对约数的研究中. 对于一个数X,函数f(X)表示X所有约数的和.例如:f(6)=1+2+3+6=12.对于一个X,Smart可以很快的算出f(X) ...

  3. Xcode 6以上版本如何创建一个空的工程(Empty Application)

    Xcode 6 正式版里面没有Empty Application这个模板,这对于习惯了纯代码编写UI界面的程序员来说很不习惯. 有高手给出了一个解决方法是,把Xcode 6 beta版里面的模板复制过 ...

  4. uva 10723 Cyborg Genes(LCS变形)

    题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=107450#problem/C 题意:输入两个字符串,找一个最短的串,使得输入的两个 ...

  5. 锋利的jQuery-5--下拉框的应用(看写法)

    如图,可以通过中间的按钮将左边选中的选项添加到右边,或者全部添加到右边,也可通过双击添加.反之也可以. 左边选中加到右边: $("#add").click(function(){ ...

  6. pthread 学习系列 case2-- 使用互斥锁

    ref http://www.ibm.com/developerworks/cn/linux/thread/posix_thread1/index.html #include <pthread. ...

  7. NC反弹CMDSHELL提权总结

    Server-U等都不可以用的情况下.   一般都可思考用此方法不过这种方法, 只要对方装了防火墙, 或是屏蔽掉了除常用的那几个端口外的所有端口…   那么这种方法也失效了…. 1:通过shell将上 ...

  8. c/s架构nginx+php-fpm通信原理

        FastCGI是一个运用于Http Server和动态脚本语言间通信的接口,多数流行的Http Server都支持FastCGI,包括Apache.Nginx和lighttpd等.同时,Fas ...

  9. Linux里如何查找文件内容 (转)

    Linux查找文件内容的常用命令方法. 从文件内容查找匹配指定字符串的行: $ grep "被查找的字符串" 文件名例子:在当前目录里第一级文件夹中寻找包含指定字符串的.in文件g ...

  10. Java-UDP Socket编程

    UDP 的 Java 支持 UDP 协议提供的服务不同于 TCP 协议的端到端服务,它是面向非连接的,属不可靠协议,UDP 套接字在使用前不需要进行连接.实际上,UDP 协议只实现了两个功能: 在 I ...