Climbing the HillTime

** limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)**

Total submission (s): 1218 Accepted Submission (s): 548

Problem Descriptionalice 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 is several persons at different cells, and there is one special people, which is, the king. The persons can ' t occupy the same cell, except the hilltop.

At one move, the player can choose any person, and who isn't 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 moves the king to the hilltop would win.

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

Inputthere is several test cases. The first line of all test case contains-integers n and k (1 <= n <=, 1 <= k <= N), indicating that There is N persons on the

Hill, and the king are 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 the most, and so on.) These N integers is ordered increasingly, more than 0 and less than 100000.

Outputif Alice can win, output "Alice". If not, output "Bob".

Sample Input

3 31 2 42 1100 200

Sample Output

Bobalice*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 in cell 1 or cell 4 one step up, but it's not allowed to move the person on CE LL 2.

Authortju

Source2012 multi-university Training Contest 2

Test instructions

There are n individuals climbing mountains, the peak coordinates of 0, the coordinates of others are given in ascending order. The coordinates can only hold one person (the top of the mountain), and Alice and Bob take turns choosing a person to move him any step, but not over the person in front. Now there is a man who is king (given the ID), who can move King to the top even if he wins.

Analysis

Considering King's situation is almost consistent with the above version, as long as king is treated like a normal person.

In addition to two special cases:

1. When King is the first person, Alice wins directly

2. When King is a second person and has an odd number of people, the size of the first pile needs to be reduced by 1.

Because if King is on an odd stone, then the pair of stones in front of King K1,k2.

When the other person moves the K1 to top, I can move the K2 to a position in front of the top.

So for K2 Stone, if the other side touches it, then I will definitely move King to top.

So K2 is also equivalent to a waste son, does not affect the results of the final NIM.

Ps: Ladder Game Learning Blog Link: Ladder game

#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 (b) memset (A,b,sizeof (a)) #define Lson (i<& lt;1) #define Rson ((i<<1) | \) #define N 50010int 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;}

hdu4315 Climbing the Hill (ladder game)