Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1286 Accepted Submission(s): 585

Problem 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.

【题目链接】:http://acm.hdu.edu.cn/showproblem.php?pid=4315

【题解】

/*
也是个阶梯博弈;
和上一篇文章类似;
如果不考虑那个king的话;
同时把要求改为最后一个把棋子弄到山顶的人赢;
则方法和上一篇文章一样;
这里复制一下上篇文章的地址:http://blog.csdn.net/harlow_cheng/article/details/54140110
写得很详细了;
稍有不同的是;
奇数的时候;
第一个棋子能够往前移动的距离应该是a[1]而不是a[1]-1了;
因为要弄到山顶(可以看成是坐标为0的地方)而不是弄到坐标为1;
(以下内容你真的得先看过上面那篇地址里面的文章后才能看得懂);
接下来考虑那个king存在的情况;
先不考虑K=1和(N为奇数且K=2的情况);因为有些特殊;
先考虑普通的;
不如假设N为偶数(奇数的等下讨论);
然后对K(这里假设K>2)分类讨论;
①K为偶数
1 5 6 7 9 12 14 17
->(1 5) (6 7) (9 12) (14 17)
这里不妨假设在每个组合的右边都不能移动后,它们排成了一列(显然是可以的);
->(1 2) (3 4) (5 6) (7,8)
这样NIM的各个堆的大小都为0了;
接下来要进行操作的人肯定是输的;
因为K为偶数,所以肯定是组合中的右边那个;
而接下来就要进行操作的人每次显然不可能先把右边的拿到山顶去;
②K为奇数
也是一样
假设最后变成了这样
->(1 2) (3 4) (5 6) (7,8)
假设k=3
则我们在对手把1拿到山顶后(只有这个可行操作了);
把2先不拿到山顶;
先放到1位置;即
这里的0表示没有棋子;
2 0 (3 4) (5 6) (7,8)
那么接下来对手肯定不能操作2号棋子;
不然我们肯定能赢;
如果对手操作3号棋子(往左移动一位);
则我们把4号也跟着往左移动一位;
总之跟着它搞;
最后对方肯定不得不操作那个2号棋子往左移动一位;
那么我们机会就来了;
潇洒地把K=3号棋子拿到山顶:)
接下来考虑N为奇数的情况;
比如N=3
3 6 16
其对应
(0 3) (6 16)
注意其对应的NIM堆为3 9
因为和前一篇文章的不同这里的3可以移到山顶!;
那么还是一样做NIM游戏;
最后会变成(假设除了第一个石子外,其他石子的组合的左边没有移动到山顶);
0 0 1 2
分类K(注意我们先考虑K>2)

K=奇数,比如上例的K=3(这里的3就是上面的2号棋子);
显然对手必须得把1号棋子往左移动;咱们还是一样能赢;

K=偶数的话类似
这里我们只要把K号棋子所在的组合的前面一个组合的右边那个
按照上面的讨论
先放在1号位置;
这样咱们就总能把K号棋子放到山顶了(当然前面的NIM游戏得是你必赢才行)
接下来再考虑
K=1;
显然K=1的时候先手赢;
接下来再考虑
N为奇数,K=2的情况
这里以上面的
3 6 16为例子
按照正常的思路
(0 3) (6 16)
我们会算成
3 9 那就表示第一个石子在做NIM游戏的过程中是可以往左移动3格的;
但是,如果这样的话,对手不管怎么样都能直接把K=2号棋子直接移动到
山顶(因为1号棋子已经被你移动到山顶了,唯一能挡住2号棋子的棋子已经没
了);
那么你再进行NIM游戏也没有意义了;
所以在N为奇数K=2的情况下;
我们应该把虚构的一个组合的NIM游戏的堆减少1;
这就表示1号棋子不会在做NIM游戏的过程中直接移动到山顶;

(0 3) (6 16)
->2 9
这样,假设大家都不把棋子移动到山顶就会最终变为
0 1 2 3 4
这样1号棋子总是挡着2号棋子的;
那么接下来要移动棋子的人就输了;(你没办法躲了肯定输);
而上面N为奇数,但是K>2,
所以最终可以变成
0 0 1 2
这里比如K=3就没关系了,因为有个1在前面挡着,不会在没做完NIM游戏的时候就
决定了胜负;(除非你作死自己把1号棋子移动到了山顶),当然如果是你知道了NIM
游戏的胜负自暴自弃除外。:)
综上加了一个国王,只是添加几个特殊的判定而已;
要注意如果最后是要求移动到下标为0的地方,和下标为1的地方,N为奇数的时候;新构造处理的那个组合所代表的NIM堆的大小有差别;
*/

【完整代码】

#include <bits/stdc++.h>
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};
const double pi = acos(-1.0); int n,k;
int a[MAXN]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
while (~scanf("%d%d",&n,&k))
{
int temp = 0;
rep1(i,1,n)
rei(a[i]);
if (k==1)
puts("Alice");
else
{
int ju = n&1;
if (ju && k==2)
a[0] = 0;
else
a[0] = -1;
rep1(i,1,n)
if ((i&1)==ju)
temp ^= a[i]-a[i-1]-1;
if (temp==0)
puts("Bob");
else
puts("Alice");
}
}
return 0;
}

【hdu 4315】Climbing the Hill的更多相关文章

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

    http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:有n个人要往坐标为0的地方移动,他们分别有一个位置a[i],其中最靠近0的第k个人是king,移动的 ...

  2. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  3. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  4. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  5. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  6. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  7. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  8. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  9. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

随机推荐

  1. jmeter分布式测试的坑(转)

    本文转自:https://www.cnblogs.com/lsjdddddd/p/5806077.html 有关jmeter分布式测试的环境配置,大概就是那样,但是每次想要进行jmeter分布式测试的 ...

  2. 【例题 8-4 UVA - 11134】Fabled Rooks

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然把问题分解成两个子问题. x轴和y轴分别做. 即n个点要求第i个点在[li,ri]范围内.(ri<=n) 问是否可行. 按 ...

  3. 洛谷 P1893 山峰暸望

    P1893 山峰暸望 题目描述 一天,Bessie在眺望美丽的威斯康星的群山的时候,她突然产生了疑问:那座山是最宽的? 她决定在地平线上,利用她的新式大量程山峰高度测量仪依次做N (1 <= N ...

  4. Android Notification.setLatestEventInfo弃用和Notification.Builder用法

    今天在学习小米便签的源码的时候,至于源码的地址,http://m.blog.csdn.net/article/details?id=50544248 ,里面有好多github的开源项目,打开项目,报错 ...

  5. mysql中配置ssl_key、ssl-cert、ssl-ca的路径及建立ssl连接(适用于5.7以下版本,5.7及以上请看本文末尾的备注)

    1.创建 CA 私钥和 CA 证书 (1)下载并安装openssl,将bin目录配置到环境变量: (2)设置openssl.cfg路径(若不设置会报错,找不到openssl配置文件) \bin\ope ...

  6. vc如何让打开的子窗口默认是最大化的

    vc如何让打开的子窗口默认是最大化的 浏览: 3554 | 更新: 2011-04-09 17:04 1 0     加入杂志加入杂志 摘要:关于vc如何让打开的子窗口默认是最大化的深入研究.   步 ...

  7. Fragment事务管理源代码分析

    转载请标明出处:http://blog.csdn.net/shensky711/article/details/53132952 本文出自: [HansChen的博客] 概述 在Fragment使用中 ...

  8. hdu5384 AC自己主动机模板题,统计模式串在给定串中出现的个数

    http://acm.hdu.edu.cn/showproblem.php?pid=5384 Problem Description Danganronpa is a video game franc ...

  9. 基于ContentObserver来动态取消或加入屏幕超时任务

    前面也说了.ContentObserver能够来监控数据库里某一项数据的变化,当然也能够同一时候监控多个数据项的变化. 笔者在项目中须要改动到屏幕超时的需求,比方在车载业务中,倒车事件发生的时候,是不 ...

  10. Instant Client 配置

    Instant Client Download 选择  Instant Client for Microsoft Windows (32-bit)  由于PL/SQL Developer 不支持64b ...