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

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

送人，条件是不能跨越前面最近的人，问在Alice先手，双方最优的条件下谁能把King送到山顶。

选择，所以hill[1]--。

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

1.假设n=5，k=2。1, 2，5， 6，10。 三堆是0,2,3。先手必胜。先手走成0,2,2让后手面对必败态，后手可以把局面走成0,0,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即可。

```#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)
{
],ans=;
; i<=n; i++)
cin>>a[i];
a[]=;
)
{
cout<<"Alice"<<endl;
continue;
}
) a[]=-; //只有当n为奇数的时候才会涉及到a[0] 因为a[1]单成一堆
//意为正常0到a[1]这个堆就应该是a[1]-1的 但是k不在2的时候a[1]可以移动到0
//比正常的堆多一个位置 所以要-(-1)=+1
; 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);
}
;
}```

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

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

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

2. hdu 4315 Climbing the Hill（阶梯博弈转nim博弈）

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

3. hdu 4315 Climbing the Hill 博弈论

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

4. hdu 1849 （尼姆博弈）

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

5. hdu 1849（Rabbit and Grass） 尼姆博弈

Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

6. HDU 2176 取(m堆)石子游戏 尼姆博弈

题目思路: 对于尼姆博弈我们知道:op=a[1]^a[2]--a[n],若op==0先手必败 一个简单的数学公式:若op=a^b 那么:op^b=a: 对于第i堆a[i],op^a[i]的值代表其余各 ...

7. Being a Good Boy in Spring Festival 尼姆博弈

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

8. hdu-------(1848)Fibonacci again and again(sg函数版的尼姆博弈)

Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

9. hdu----(1849)Rabbit and Grass（简单的尼姆博弈）

Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

## 随机推荐

1. [LeetCode] Insert Delete GetRandom O(1) - Duplicates allowed 常数时间内插入删除和获得随机数 - 允许重复

Design a data structure that supports all following operations in average O(1) time. Note: Duplicate ...

2. Linux收藏

Unix目录结构的来历   vi 操作笔记  Linux下安装和配置JDK与Tomcat(升级版) Windows下 刷新本地DNS缓存:ipconfig /flushdns 深圳DNS: 202.9 ...

3. c++调用lua环境配置

安装完luaforwindows后进行配置 配置项目属性

4. ToString()的各种用法（大全）

常用例子: string str = ""; str = .ToString("N"); //生成 12,3456.00 str = .ToString(&qu ...

5. VC++6.0编译器标记的那些内存值

栈内存初始值 0xcccccccc 和-858993460.   二者是一样的, 一个是16进制, 另一个是10进制

6. 20145320《Java程序设计》第9周学习总结

20145320<Java程序设计>第9周学习总结 教材学习内容总结 16.整合数据库 JDBC(java DateBase Connectivity)是用于执行SQL的解决方案,开发人员 ...

7. 3种归并操作js代码

/**良哥的*/ function merge(a, b) { var aLen = a.length, bLen = b.length, maxLen = Math.max(aLen, bLen), ...

8. jQuery的事件click

不管是在asp.net 还是asp.net mvc中,对象的click事件是我们最常用到的一个事件,说明用户click点击一下mouse的左键,铵下并放开的事件. 今天已经是十一月份了,学习又是新的开 ...

9. 微软Asp.net MVC5生命周期流程图

.NET WEB Development blog 发布了Asp.net MVC5生命周期文档, 这个文档类似Asp.net应用程序生命周期,您以前开发ASP.NET WEB应用程序应该 ...

10. javascript中的 类初始化，遍历for in 以及with的用法

<script type="text/javascript"> function member(name,gender){ this.name=name; this.g ...