FZU Problem 1534 阿甘的珠宝 (博弈)

题目:http://acm.fzu.edu.cn/problem.php?pid=1534

巴什博奕和尼姆博弈的综合。

这里分为最后拿胜利,最后拿失败,分别是nim 和 anti-nim。

SG(n) =  n%3

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int maxn = 10005;
int p[maxn];
int main(){
    int n;
    while(~scanf("%d",&n)){
        int cnt = 0;
        for(int i = 0;i < n;i++){
            scanf("%d",p+i);
            if(p[i] > 1)cnt++;
            p[i] %= 3;
        }
        int q,ans = 0;
        scanf("%d",&q);
        for(int i = 0;i < n;i++)
                ans ^= p[i];
        if(q){
            if ((!cnt&&!ans) || (cnt&&ans))
                printf("yes\n");
            else
                printf("no\n");
        }
        else{
            if(ans)
                printf("yes\n");
            else
                printf("no\n");
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Roly/p/3081787.html