首页 > 其他 > 详细

POJ 3480 John(SJ定理博弈)题解

时间:2018-09-21 23:50:57      阅读:168      评论:0      收藏:0      [点我收藏+]

题意:n堆石头,拿走最后一块的输

思路:SJ定理:先手必胜当且仅当:(1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1;(2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1。

参考:【博弈】Anti,Multi,Every-SG

代码:

#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
typedef long long ll;
const int maxn = 4747 + 10;
const int seed = 131;
const ll MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
int main(){
    int T, n;
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        int ans = 0, flag = 0, u;
        while(n--){
            scanf("%d", &u);
            ans ^= u;
            if(u > 1) flag = 1;
        }
        if(ans){
            if(flag) printf("John\n");
            else printf("Brother\n");
        }
        else{
            if(flag) printf("Brother\n");
            else printf("John\n");
        }
    }
    return 0;
}

 

POJ 3480 John(SJ定理博弈)题解

原文:https://www.cnblogs.com/KirinSB/p/9688806.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!