hdu 3389 Game<阶梯博弈>

链接: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
 1 #include <iostream>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <string>
 6 #include <stdlib.h>
 7 #include <algorithm>
 8 using namespace std;
 9 typedef long long LL;
10 const LL Mod= 1e9+7;
11 int T, N, Ca, x; 
12 int main( )
13 {
14     scanf( "%d", &T );
15     while( T -- ){
16         printf( "Case %d: ", ++Ca );
17         scanf( "%d",&N );
18         int ans=0;
19         for( int i=1; i<=N; ++ i ){
20             scanf( "%d", &x );
21             if( i%6==0 || i%6==5 || i%6==2 ){
22                 ans^=x;
23             }
24         }
25         if( ans )puts( "Alice" );
26         else puts( "Bob" );
27     }
28     return 0;
29 }

 

 

 

 

 

posted @ 2013-04-29 14:50  淡墨æ末央  阅读(228)  评论(1)    收藏  举报