hdu4315 Climbing the Hill(阶梯博弈)

Climbing the Hill

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


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
 

题意】

有N个人爬山,山顶坐标为0,其他人的坐标按升序给出。不同的坐标只能容纳一个人(山顶不限),Alice和Bob轮流选择一个人让他移动任意步,但不能越过前面那个人。现在有一个人是king(给出id),谁能将king移动到山顶就算赢。

【分析】

考虑King的情况和上述版本几乎一致,只要把King当作普通人一样处理即可。
除了两种特殊情况:
1. 当King是第一个人时,Alice直接胜
2. 当King是第二个人且一共有奇数个人时,第一堆的大小需要减1。
因为如果king在奇数石子上,那么king前面的那一对石子k1,k2.
当对方把k1移到top时,我可以把k2移到top前的一个位置.
那么对于k2石子,对方如果碰了它,那么我肯定会把king移到top的.
所以k2也相当于是一颗废子而已,不影响最终Nim的结果.


Ps:阶梯博弈学习博客链接:阶梯博弈

 

#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 1e9;
const int MOD = 1e9+7;
#define ll long long
#define CL(a,b) memset(a,b,sizeof(a))
#define lson (i<<1)
#define rson ((i<<1)|1)
#define N 50010
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n,k;
int s[1010];

int main()
{
    while(scanf("%d%d",&n,&k)==2)
    {
        for(int i=1; i<=n; i++)
            scanf("%d",&s[i]);
        if(k == 1) {cout<<"Alice"<<endl; continue;}
        int ans;
        if(n%2 == 0)
        {
            ans = s[2]-s[1]-1;
            for(int i=4; i<=n; i+=2) ans ^= (s[i]-s[i-1]-1);
            if(ans == 0) cout<<"Bob"<<endl;
            else cout<<"Alice"<<endl;
        }
        else
        {
            ans = s[1];
            if(k == 2) ans -= 1;
            for(int i=3; i<=n; i+=2) ans ^= (s[i]-s[i-1]-1);

            if(ans == 0) cout<<"Bob"<<endl;
            else cout<<"Alice"<<endl;
        }
    }
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值