hdu 3389 阶梯博弈

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

  
阶梯博弈:博弈在一列阶梯上进行,每个阶梯上放着自然数个点,两个人进行阶梯博弈,每一步则是将一个集体上的若干个点

( >=1 )移到前面去,最后没有点可以移动的人输。


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

, 8->1 9->6,10->5 11->4.. 15->6..

11->4 12->3 14->1
17->4 19->3 20->1
...

位置i%6 == 0 2 5的 这些位置 能移到1 3 4上 这样就相当于是在这几个位置上做nim博弈

Sample Input
2
2
1 2
7
1 3 3 2 2 1 2

Sample Output
Case 1: Alice
Case 2: Bob

 1 # include <iostream>
 2 # include <cstdio>
 3 # include <cstring>
 4 # include <algorithm>
 5 # include <string>
 6 # include <cmath>
 7 # include <queue>
 8 # include <list>
 9 # define LL long long
10 using namespace std ;
11 
12 int main()
13 {
14     //freopen("in.txt","r",stdin) ;
15     int T ;
16     scanf("%d" , &T) ;
17     int Case = 0 ;
18     while(T--)
19     {
20         int n , x ;
21         int i ;
22         Case++ ;
23         printf("Case %d: " , Case) ;
24         scanf("%d" , &n) ;
25         int ans = 0 ;
26         for (i = 1 ; i <= n ; i++)
27         {
28             scanf("%d" , &x) ;
29             if (i%6==0 ||i%6==2 ||i%6==5)
30                 ans ^= x ;
31         }
32         if (ans == 0)
33             printf("Bob
") ;
34         else
35             printf("Alice
") ;
36 
37     }
38 }
View Code
原文地址:https://www.cnblogs.com/mengchunchen/p/4856581.html