zoukankan      html  css  js  c++  java
  • POJ 3480 John(SJ定理博弈)题解

    题意: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
    ");
                else printf("Brother
    ");
            }
            else{
                if(flag) printf("Brother
    ");
                else printf("John
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    合并字符串中的多个空格
    IfcSpecularRoughness
    IfcSpecularExponent
    IfcPresentableText
    IfcFontWeight
    IfcFontVariant
    uwb ifc模型定位測試
    IfcFontStyle
    IfcGeometricModelResource
    qt6安装
  • 原文地址:https://www.cnblogs.com/KirinSB/p/9688806.html
Copyright © 2011-2022 走看看