hdu1907(anti-sg入门)

改变了下规则,现在变成了最后拿的人输。

如果对于单纯的nim的话,只需要判断每堆都是1个石子的特殊情况。

因为如果存在有大于1个石子的堆话,类似于nim的取法,处于必胜状态的一方只需要在 对方取完后只剩下一堆>1石子的堆中,选择留下奇数个大小为1的堆或偶数个大小为1的堆。

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

int main()
{
    int T;
    cin>>T;
    while(T--){
        int n;
        scanf("%d",&n);
        int cnt = 0;
        int ans = 0;
        for(int i=0;i<n;i++)
        {
            int tmp;
            scanf("%d",&tmp);
            if(tmp==1) cnt++;
            ans^=tmp;
        }
        int flag = 0;
        if(cnt==n && ans==0)
        {
            flag = 1;
        }
        else if(cnt!=n && ans!=0) flag= 1;
        if(flag) printf("John
");
        else printf("Brother
");
        
    }
    return 0;
}
原文地址:https://www.cnblogs.com/chenhuan001/p/5765476.html