您的位置:首页 > 其它

hdu 4315 Climbing the Hill(阶梯博弈转nim博弈)

2014-10-25 10:30 369 查看

Climbing the Hill

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

[align=left]Problem Description[/align]
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.

#include<cstring>
#include<cstdio>
#include<cstdlib>
int aa[1005];
int n,k;
int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
for(int i=0;i<n;i++)
scanf("%d",&aa[i]);
int ans=0;
if(k==1)
{
puts("Alice");
continue;
}
if(n%2==0)  //偶数堆
{
for(int i=1;i<n;i+=2)
ans^=(aa[i]-aa[i-1]-1);
}
else
{
if(k==2) ans=aa[0]-1;
else     ans=aa[0];
for(int i=2;i<n;i+=2)
ans^=(aa[i]-aa[i-1]-1);
}
if(ans)  puts("Alice");
else puts("Bob");
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: