hdu4315 Climbing the Hill

来源:互联网 发布:天下3男号捏脸数据 编辑:程序博客网 时间:2024/04/29 00:17

Climbing the Hill

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


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 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 on cell 1 or cell 4 one step up, but it is not allowed to move the person on cell 2.
这题,虽然和上一题的博弈是一样的,也可以转化成上一题中的,移动石子,但是,有一个问题老是想不明白,为什么这一题,是奇数且为第二个的时候,会是特殊情况,以后再想吧!
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;#define M 1005int pri[M];int main(){    int n,k,ans,i;    while(scanf("%d%d",&n,&k)!=EOF){        for(i=1;i<=n;i++)        scanf("%d",&pri[i]);        if(k==1){            printf("Alice\n");            continue;        }        ans=0;i--;        while(i>1){            ans^=(pri[i]-pri[i-1]-1);i=i-2;        }        if(n&1){            if(k==2)            ans^=(pri[1]-1);            else ans^=pri[1];        }        if(ans)printf("Alice\n");        else printf("Bob\n");    }    return 0;}


原创粉丝点击