码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-09-22 00:52:15      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:cstring   题解   mod   mes   \n   ack   long   scanf   eve   

题意: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定理博弈)题解

标签:cstring   题解   mod   mes   \n   ack   long   scanf   eve   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!