题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1714

nim游戏的一个变形,需要打出sg函数的表

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

;
], maxs;
int vis[maxn];

//yu控制递归层数,cur控制所分配最大值,next控制所分配最小值
void dfs(int cur, int yu, int ans, int next)
{
    )
    {
        vis[ans]=;
        return ;
    }
    for(int i=next; i<cur; i++)
        dfs(cur, yu-, ans^sg[i], i);
}
void init()
{
    sg[]=;
    ;i<=; i++)
    {
        memset(vis,,sizeof(vis));
        dfs(i, , , );
        ;;j++)
            if(!vis[j])
            {
                sg[i]=j;
                break;
            }
        printf("%d\n", sg[i]);
    }
}
void print(int n)
{
    ;i>=;i--)
    {
        ) cout<<;
        ;
    }
    cout<<endl;
}

int main()
{
    init();
    ;i<;i++)
        print(sg[i]);
}
//Process exited after 232.7 seconds with return value 0 
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long uLL;

, , , , , , , , , , , ,
            , , , , , , , ,
            , , , , , , ,
            , , , , , ,
            , , , , , ,
            , , , , , ,
            , , , , , ,
            , , , , , ,
            , , , , ,
            , ,
           };

int cal(uLL x)
{
    ;
    ;i<;i++)
        ) ret++;
    return ret;
}
int main()
{
    int n;
    while(cin>>n)
    {
        ;
        while(n--)
        {
            uLL t;
            cin>>t;
            ans ^= sg[cal(t)];
        }
        if(ans) puts("B");
        else puts("L");
    }
}

51nod 1714:B君的游戏(博弈 sg打表)的更多相关文章

  1. 51Nod - 1714 B君的游戏

    每个数的SG值之和他有多少个1相关 打表复杂度:找K个有序的<n的非负数的复杂度为nk/(k!) 则这题的SG打表复杂度为648/7! 为1e10左右 void dfs(int cur, int ...

  2. 1714 B君的游戏(Nim博弈)

    1714 B君的游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 B君和L君要玩一个游戏.刚开始有n个正整数  ai  . 双方轮流操作.每次操作,选一个正整数 ...

  3. 51nod_1714:B君的游戏(博弈 sg打表)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1714 nim游戏的一个变形,需要打出sg函数的表 #incl ...

  4. 51nod 1661: 黑板上的游戏(sg函数 找规律)

    题目链接 先打一个sg函数的表,找找规律,发现sg函数可以递归求解 打表代码如下 #include<bits/stdc++.h> using namespace std; typedef ...

  5. hihoCoder hiho一下 第四十六周 博弈游戏·Nim游戏·三( sg函数 )

    题意: 给出几堆石子数量,每次可以取走一堆中任意数量的石头,也可以将一堆分成两堆,而不取.最后取走者胜. 思路: 先规矩地计算出sg值,再对每个数量查SG值就可以了.最后求异或和.和不为0的就是必赢. ...

  6. 博弈SG

    先转一篇看得比较懂的,以后有时间自己再归纳下 转自:http://blog.csdn.net/logic_nut/article/details/4711489 博弈问题若你想仔细学习博弈论,我强烈推 ...

  7. (博弈 sg入门2)

    接下来介绍Nim游戏(同样引用杭电上的,懒的打字) 1.有两个玩家:   2.  有三堆扑克牌(比如:可以分别是    5,7,9张):  3. 游戏双方轮流操作:  4. 玩家的每次操作是选择其中某 ...

  8. Nim 游戏、SG 函数、游戏的和

    Nim游戏 Nim游戏定义 Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impartial Combinatorial Games”(以下简称ICG).满足以 ...

  9. Nim游戏与SG函数 ——博弈论小结

    写这篇博客之前,花了许久时间来搞这个SG函数,倒是各路大神的论文看的多,却到底没几个看懂的.还好网上一些大牛博客还是性价比相当高的,多少理解了些,也自己通过做一些题加深了下了解. 既然是博弈,经典的N ...

随机推荐

  1. eclipse 启动 tomcat 报错:Server mylocalhost was unable to start within 45 seconds

    这个专门转载一篇博文也是为了讽刺一下自己二逼的程序员职业,哈哈. eclipse启动tomcat服务器报错:Server mylocalhost was unable to start within ...

  2. (转)Kubernetes 配置Pod和容器(十七) 使用Secrets管理安全证书

    转:https://www.jianshu.com/p/530b3642c642 本章节展示了如何把密码秘钥等敏感数据安全的注入到Pod里面. 转换安全数据成base-64表示 假设你有两个秘密数据: ...

  3. 牛客网暑期ACM多校训练营(第五场) F - take —— 期望+树状数组+逆元

    看到一篇好的博客特意转出来观摩大佬:转:https://blog.csdn.net/greybtfly/article/details/81413526 题目大意:给n个箱子排成一排,从头到尾按顺序依 ...

  4. php面试专题---18、MySQL查询优化考点

    php面试专题---18.MySQL查询优化考点 一.总结 一句话总结: 慢查询:查找分析查询速度慢的原因 数据访问:优化查询过程中的数据访问 长难句:优化长难的查询语句 特定类型:优化特定类型的查询 ...

  5. JavaScript 获取随机整数

    Math.random()方法会返回介于 0(包含) ~ 1(不包含) 之间的一个随机数 假如想要拿到0-10之间的数,只需要将该方法的值*10 即Math.random()*10: 假如想要拿到0- ...

  6. C#连redis

    引入 Microsoft.Extensions.Caching.Redis其实就是封装了StackExchange.redis 控制台例子: class Program { public static ...

  7. Gradle查看Project中的所有 Task

    查看Project中所有的Task:$ gradle tasks 查看Project中所有的properties:$ gradle properties 如: 参照了: https://www.jia ...

  8. Validform验证插件

    http://validform.club/index.html

  9. poj1742Coins(多重背包)

    People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony ...

  10. Jmeter-后置处理器(Json extractor)

    后置处理器-json extractor 概念:顾名思义,提取json响应的数据中提取数据: 步骤:sampler-后置处理器-jsonextractor 1.提取单个参数 1.Variable na ...