Climbing the Hill

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 919    Accepted Submission(s): 411

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.

 
Author
TJU
 
Source
 
代码:
 #include<cstring>
#include<cstdio>
#include<cstdlib>
int aa[];
int n,k;
int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
for(int i=;i<n;i++)
scanf("%d",&aa[i]);
int ans=;
if(k==)
{
puts("Alice");
continue;
}
if(n%==) //偶数堆
{
for(int i=;i<n;i+=)
ans^=(aa[i]-aa[i-]-);
}
else
{
if(k==) ans=aa[]-;
else ans=aa[];
for(int i=;i<n;i+=)
ans^=(aa[i]-aa[i-]-);
}
if(ans) puts("Alice");
else puts("Bob");
}
return ;
}

hdu 4315 Climbing the Hill(阶梯博弈转nim博弈)的更多相关文章

  1. HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)

    Climbing the Hill Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Su ...

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

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

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

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

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

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

  5. hdu 4315 Climbing the Hill 博弈论

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

  6. HDU 2176:取(m堆)石子游戏(Nim博弈)

    取(m堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  7. HDU Rabbit and Grass 兔子和草 (Nim博弈)

    思路:简单Nim博弈,只需要将所给的数字全部进行异或,结果为0,则先手必败.否则必胜. #include <iostream> using namespace std; int main( ...

  8. HDU 2176 取(m堆)石子游戏 —— (Nim博弈)

    如果yes的话要输出所有情况,一开始觉得挺难,想了一下也没什么. 每堆的个数^一下,答案不是0就是先取者必胜,那么对必胜态显然至少存在一种可能性使得当前局势变成必败的.只要任意选取一堆,把这堆的数目变 ...

  9. 博弈论中的Nim博弈

    瞎扯 \(orzorz\) \(cdx\) 聚聚给我们讲了博弈论.我要没学上了,祝各位新年快乐.现在让我讲课我都不知道讲什么,我会的东西大家都会,太菜了太菜了. 马上就要回去上文化课了,今明还是收下尾 ...

随机推荐

  1. Cheatsheet: 2014 03.01 ~ 03.31

    .NET Should I be concerned about PDB files? async and await -Simplified-Internals Web Performance tr ...

  2. FreeSWITCH的传真发送

    详细的学习请参考:https://wiki.freeswitch.org/wiki/Mod_spandsp 我只说说WIKI上没有直接写出来却又很实用的东西. 一.传真收发 环境大致如下: FreeS ...

  3. scp指令的学习

    http://www.cnblogs.com/hitwtx/archive/2011/11/16/2251254.html scp是linux中功能最强大的文件传输命令,可以实现从本地到远程以及远程到 ...

  4. servlet&jsp高级:第五部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. Codeforces Round #249 (Div. 2) A题

    链接:http://codeforces.com/contest/435/problem/A   A. Queue on Bus Stop time limit per test 1 second m ...

  6. NS_ASSUME_NONNULL_BEGIN,NS_ASSUME_NONNULL_END

    Nonnull区域设置(Audited Regions) 如果需要每个属性或每个方法都去指定nonnull和nullable,是一件非常繁琐的事.苹果为了减轻我们的工作量,专门提供了两个宏:NS_AS ...

  7. hdu 5167 Fibonacci 打表

    Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Proble ...

  8. SQL查询语句 group by后, 字符串合并

    合并列值 --******************************************************************************************* 表 ...

  9. JS 实现新浪微博, QQZone 等的分享

    <script type="text/javascript">window.pageConfig = { compatible: true,searchType: 1 ...

  10. 批量创建客户主数据函数SD_CUSTOMER_MAINTAIN_ALL

    分享一下批创建客户主数据函数:SD_CUSTOMER_MAINTAIN_ALL TABLES:T077D,ZCITY,T005S,BNKA,ADRC,KNA1.  DATA: TMP_KTOKD(4) ...