hdu 4315 Climbing the Hill 博弈论
2013-08-21 22:10
302 查看
题意:有n个人爬山,山顶坐标为0,其他人按升序给出,不同的坐标只能容纳一个人(山顶不限),Alice和Bob轮流选择一个人让他移动任意步,但不能越过前面的人,且不能和前面一个人在相同的位置。现在有一个人是king,给出king是哪个人(id),谁能将国王移动到山顶谁胜。
解题思路:先考虑简化版,没有king,谁先不能移动谁输掉。和阶梯博弈类似http://blog.csdn.net/longshuai0821/article/details/7793043。根据人数的奇偶性:把人从上顶向下的位置记为a1,a2,...an, 如果为偶数个人,则把a(2i-1)和a(2i)之间的距离-1(空格数)当做一个Nim堆,变成一共n/2堆的Nim游戏;如果为奇数个人,则把山顶到a1的距离(这是距离)当做一个Nim堆,a(i*2)到a(i*2+1)的距离-1当做Nim堆,一共(n+1)/2堆,相当于往后面(山下)移动石子(从山上到山下是一个阶梯,石子向山下传递)。
考虑King的情况和上述版本几乎一致,只要把King当作普通人一样处理即可。除了两种特殊情况:1. 当King是第一个人时,Alice直接胜 2. 当King是第二个人且一共有奇数个人时,第一堆的大小需要减1。
代码如下:
View Code
解题思路:先考虑简化版,没有king,谁先不能移动谁输掉。和阶梯博弈类似http://blog.csdn.net/longshuai0821/article/details/7793043。根据人数的奇偶性:把人从上顶向下的位置记为a1,a2,...an, 如果为偶数个人,则把a(2i-1)和a(2i)之间的距离-1(空格数)当做一个Nim堆,变成一共n/2堆的Nim游戏;如果为奇数个人,则把山顶到a1的距离(这是距离)当做一个Nim堆,a(i*2)到a(i*2+1)的距离-1当做Nim堆,一共(n+1)/2堆,相当于往后面(山下)移动石子(从山上到山下是一个阶梯,石子向山下传递)。
考虑King的情况和上述版本几乎一致,只要把King当作普通人一样处理即可。除了两种特殊情况:1. 当King是第一个人时,Alice直接胜 2. 当King是第二个人且一共有奇数个人时,第一堆的大小需要减1。
代码如下:
#include<iostream> #include<cstdlib> #include<stdio.h> using namespace std; int a[1001]; int main() { int i,k,n,t; a[0]=-1; while(scanf("%d%d",&n,&k)!=EOF){ for(i=1;i<=n;i++) scanf("%d",&a[i]); if(k==1){ puts("Alice"); continue; } int sg=0; for(i=n;i>0;i-=2) sg^=(t=a[i]-a[i-1]-1); if((n&1)&&k==2) sg=sg^t^(t-1); if(sg) puts("Alice"); else puts("Bob"); } return 0; }
View Code
相关文章推荐
- hdu 4315 Climbing the Hill 博弈问题,可转化为nim游戏问题,多校联合赛(二)第六题
- HDU 4315 Climbing the Hill [阶梯Nim]
- hdu - 4315 - Climbing the Hill - 博弈
- hdu 4315 Climbing the Hill(阶梯博弈转nim博弈)
- HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)
- 【hdu 4315】Climbing the Hill
- Climbing the Hill - HDU 4315 阶梯博弈变形
- hdu 4315 Climbing the Hill (阶梯博弈)
- HDU 4315 Climbing the Hill(阶梯博弈)
- HDU 4315 Climbing the Hill Staircase Nim变种
- HDU-4315 Climbing the Hill(阶梯博弈变形)
- 【hdoj 4315】Climbing the Hill
- HDOJ 题目4315Climbing the Hill(阶梯博弈)
- hdu4315 Climbing the Hill(博弈论)
- HDU 4315 Save the dwarfs 动态规划
- Climbing the Big Nan Hill
- hdu4315 Climbing the Hill(阶梯博弈)
- hdu 4155 The Game of 31 博弈论
- [HDU4315]Climbing the Hill(阶梯博弈)
- Be the Winner - HDU 2509 博弈论