首页 > ACM题库 > HDU-杭电 > HDU 4315-Climbing the Hill[解题报告]HOJ
2015
05-23

HDU 4315-Climbing the Hill[解题报告]HOJ

Climbing the Hill

问题描述 :

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.

Save the dwarfs

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

输入:

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.

输出:

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.

样例输入:

3 3
1 2 4
2 1
100 200

样例输出:

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.

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;


int num[1005];
int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k)==2)
    {
        k--;
        for(int i=0;i<n;i++)
            scanf("%d",num+i);
        if(k==0) printf("Alice\n");
        else 
        {
            if(n%2) num[n++]=k%2-1;
            sort(num,num+n);
            int sum=0;
            for(int i=0;i<n;i+=2)
                sum^=num[i+1]-num[i]-1;
            if(sum) printf("Alice\n");
            else printf("Bob\n");
        }
    }
    return 0;
}