您的位置:首页 > 其它

hdu 3389 Game<阶梯博弈>

2013-04-29 14:50 288 查看
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3389

题意::1-N带编号的盒子,当编号满足A>B && A非空 && (A + B) % 3 == 0 && (A + B) % 2 == 1则可以从A中取任意石头到B中.谁不能取了谁就输.

思路: 其本质为阶梯博弈;

  阶梯博弈:博弈在一列阶梯上进行,每个阶梯上放着自然数个点,两个人进行阶梯博弈...每一步则是将一个集体上的若干个点( >=1 )移到前面去,最后没有点可以移动的人输;

在本题中1,3,4 的状态不能转移到其他状态; 其他每个状态皆可转移; 且位置特定, 如 2->1 , 5->4, 6->3, 7->2 , 8->1 9->6.....

其本质我们有N级阶梯,现在要在 %3 的余数间转移, 0->0, 1->2, 2->1; 其最后的结果为1, 3, 4; 那么他们的转移的步数的奇偶性也会确定;

我们只要选择步数为奇数的位置做nim博弈就行了;而可以通过打表归纳证明得出模6为0、2、5的位置移动步数为奇,其余为偶;

所以~此题得解~

View Code

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <string>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL Mod= 1e9+7;
int T, N, Ca, x;
int main( )
{
scanf( "%d", &T );
while( T -- ){
printf( "Case %d: ", ++Ca );
scanf( "%d",&N );
int ans=0;
for( int i=1; i<=N; ++ i ){
scanf( "%d", &x );
if( i%6==0 || i%6==5 || i%6==2 ){
ans^=x;
}
}
if( ans )puts( "Alice" );
else puts( "Bob" );
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: