题意:

给你n堆石子,每次操作可以在任意一堆石子里取走一部分或者将这堆石子分成两堆,最后操作的人取胜。


解题思路:

利用sg定理来解组合游戏的和,每堆石子看成一个游戏,对于有x个石子的堆,它的所有后继状态有 0, 1, 2, ... , x-1 ,

(1, x-1), (2, x-2), .. (d, x-d),于是可以很容易处理出小数据的sg函数,然后可以发现4k+3的sg值为4k+4,4k+4的sg值为4k+3,其他所有x的sg值都为x,根据sg定理每堆sg值异或一下就可以解决了。


 

/* **********************************************
Author      : JayYe
Created Time: 2013-10-31 15:59:33
File Name   : JayYe.cpp
*********************************************** */

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main() {
    int t, n, x;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        int ans = 0;
        for(int i = 1;i <= n; i++) {
            scanf("%d", &x);
            if(x > 0 && x%4 == 0)
                ans ^= x-1;
            else if(x%4 == 3)
                ans ^= x+1;
            else
                ans ^= x;
        }
        if(ans) puts("Alice");
        else    puts("Bob");
    }
    return 0;
}


 

 

相关文章:

  • 2021-07-31
  • 2021-11-09
  • 2022-01-29
  • 2021-09-24
  • 2022-12-23
  • 2021-05-22
  • 2022-01-25
  • 2021-07-03
猜你喜欢
  • 2022-02-11
  • 2021-11-19
  • 2021-11-15
  • 2021-12-12
  • 2022-12-23
  • 2021-09-08
相关资源
相似解决方案