Climbing the Hill (Ladder Game---Nym Game Deformation)

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? 
InputThere 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.OutputIf 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.

The meaning of the question: There are n people on the mountain, and each person is numbered from 1 to n. These positions can only be occupied by one person at the same time, but the top of the mountain can be occupied by multiple people at the same time. The kth closest to the top of the mountain is King, and now Alice and Bob start Send people upwards, on the condition that they cannot cross the nearest person in front, and ask who can send King to the top of the mountain under the optimal conditions for Alice to move first.

There are two cases for this issue:

1. When King is in the first place, Alice wins, because Alice can directly send King to the top of the mountain.

2. When King is in the second place and the number of people n is an odd number, pair up from back to front, then the first person can only stop on a[1] at most, because if the first person climbs to the top of the mountain, then the king You can go directly to the top of the mountain, so this question can be transformed into, whoever must move the first person will lose.

At this time a[0] = 0; for example, a[1] = 2, a[0]=0 , a[1] can only move to the position of 1 so the heap is a[0]-1, and if King If it is not in the second position, then a[1] can directly move to the top of the mountain, which is one more than when King is in the second position, so let a[0] = -1, because -(-1 ) is equal to +1.

Code below:

#include <iostream>
#include <algorithm>
using namespace std;
void pr(int ans)
{
    if(ans)
        cout<<"Alice"<<endl;
    else
        cout<<"Bob"<<endl;
}
intmain()
{
    int n,k;
    while(cin>>n>>k)
    {
        int a[1005],ans=0;
        for(int i=1; i<=n; i++)
            cin>>a[i];
        a[0]=0;
        if(k==1)
        {
            cout<<"Alice"<<endl;
            continue;
        }
        if(k!=2) a[0]=-1; //a[0] is only involved when n is odd because a[1] is a bunch
        //It means that the normal 0 to a[1] heap should be a[1]-1, but when k is not 2, a[1] can be moved to 0
        //One more location than the normal heap, so -(-1)=+1
        for(int i=n; i>=1; i-=2)
            ans=ans^(a[i]-a[i-1]-1);
        pr(ans);
    }
    return 0;
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326710445&siteId=291194637