51nod 1714:B君的游戏(博弈 sg打表)
题目链接: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打表)的更多相关文章
- 51Nod - 1714 B君的游戏
每个数的SG值之和他有多少个1相关 打表复杂度:找K个有序的<n的非负数的复杂度为nk/(k!) 则这题的SG打表复杂度为648/7! 为1e10左右 void dfs(int cur, int ...
- 1714 B君的游戏(Nim博弈)
1714 B君的游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 B君和L君要玩一个游戏.刚开始有n个正整数 ai . 双方轮流操作.每次操作,选一个正整数 ...
- 51nod_1714:B君的游戏(博弈 sg打表)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1714 nim游戏的一个变形,需要打出sg函数的表 #incl ...
- 51nod 1661: 黑板上的游戏(sg函数 找规律)
题目链接 先打一个sg函数的表,找找规律,发现sg函数可以递归求解 打表代码如下 #include<bits/stdc++.h> using namespace std; typedef ...
- hihoCoder hiho一下 第四十六周 博弈游戏·Nim游戏·三( sg函数 )
题意: 给出几堆石子数量,每次可以取走一堆中任意数量的石头,也可以将一堆分成两堆,而不取.最后取走者胜. 思路: 先规矩地计算出sg值,再对每个数量查SG值就可以了.最后求异或和.和不为0的就是必赢. ...
- 博弈SG
先转一篇看得比较懂的,以后有时间自己再归纳下 转自:http://blog.csdn.net/logic_nut/article/details/4711489 博弈问题若你想仔细学习博弈论,我强烈推 ...
- (博弈 sg入门2)
接下来介绍Nim游戏(同样引用杭电上的,懒的打字) 1.有两个玩家: 2. 有三堆扑克牌(比如:可以分别是 5,7,9张): 3. 游戏双方轮流操作: 4. 玩家的每次操作是选择其中某 ...
- Nim 游戏、SG 函数、游戏的和
Nim游戏 Nim游戏定义 Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impartial Combinatorial Games”(以下简称ICG).满足以 ...
- Nim游戏与SG函数 ——博弈论小结
写这篇博客之前,花了许久时间来搞这个SG函数,倒是各路大神的论文看的多,却到底没几个看懂的.还好网上一些大牛博客还是性价比相当高的,多少理解了些,也自己通过做一些题加深了下了解. 既然是博弈,经典的N ...
随机推荐
- python 使用xlsxwriter的方法属性
http://xlsxwriter.readthedocs.io/format.html
- (转)使用windows server2008 创建 Hyper-V虚拟机
转:https://jingyan.baidu.com/article/7c6fb42833ad4980652c904f.html Hyper-v是微软提供的虚拟机,利用server 2008搭建hy ...
- 牛客提高D2t2 幸运数字考试
分析 预处理出所有合法数字 然后直接lower_bound查询即可 代码 #include<iostream> #include<cstdio> #include<cst ...
- Label设置行间距
内容摘要 UILabel显示多行文本 UILabel设置行间距 解决单行文本 & 多行文本显示的问题 场景描述 众所周知,UILabel显示多行的话,默认行间距为0,但实际开发中,如果显示多行 ...
- 测开之路七十七:性能测试蓝图之js
//定义全局的editor = nullvar editor = null; //ace_editor的初始化函数function ace_editor() { var editor = ace.ed ...
- Drone - 安装,搭配 GitLab 下的配置和使用
参考资料: Drone 官网地址:https://drone.io Drone 的 GitHub 地址:https://github.com/drone/drone 简介:https://imnerd ...
- Cross-entropy Cost Function for Classification Problem
在Machine Learning的Regression Problem中,常用Quadratic Function来做Cost Function,用以表征Hypothesis与Y之间的差距.而通过G ...
- 让Debian以root登录
Debian默认不允许root登录,所以修改之. (1)让Debian以root登录 修改gdm3的登录pam文件 #vi /etc/pam.d/gdm3 将auth required pam_suc ...
- vue里面如何让v-for循环出来的列表里面的列表click事件只对当前列表有效
<li @click="show"> <span>1</span> </li> <li @click="show&q ...
- spring cloud gateway获取response body
网关发起请求后,微服务返回的response的值要经过网关才发给客户端.本文主要讲解在spring cloud gateway 的过滤器中获取微服务的返回值,因为很多情况我们需要对这个返回进行处理.网 ...