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 ...
随机推荐
- Trailing Zeroes (III) -;lightoj 1138
Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
- 31 October
https://www.cnblogs.com/RabbitHu/p/51nod1353.html 树形 DP 求所有联通块 \(\ge K\) 的方案数. 切断:\(\forall i\in\lef ...
- Oralce-资源配置PROFILE
profile:作为用户配置文件,它是密码限制,资源限制的命名集合 在安装数据库时,Oracle自动会建立名为default的默认配置文件 使用profile文件时,要注意以下几点: 建立用户时,如果 ...
- Iterator 和 ListIterator 对比
Iterator 的方法 //是否还有下一个 boolean hasNext(); //返回下一个 E next(); //移除返回的下一个 void remove(); ListIterator 的 ...
- 【转载】Spring boot学习记录(二)-配置文件解析
前言:本系列文章非本人原创,转自:http://tengj.top/2017/04/24/springboot0/ 正文 Spring Boot使用了一个全局的配置文件application.prop ...
- 16/8/23_CSS自动换行
转载:http://blog.csdn.net/ye987987/article/details/8011875 自动换行问题,正常字符的换行是比较合理的,而连续的数字和英文字符常常将容器撑大,挺 ...
- waf学习
参考文章: http://drops.xmd5.com/static/drops/tips-7883.html waf种类 云waf 传统安全厂商的硬件waf以及一直存在ips,ids设备 主机防护软 ...
- Spring Security 01
环境搭建 maven依赖jar包 <!-- spring-security --> <dependency> <groupId>org.springframewor ...
- fastJson + lombok + 属性名命名 踩坑点
JavaBean属性名要求:前两个字母要么都大写,要么都小写 package com.jdyh.worker.project.controller; import com.alibaba.fastjs ...
- Manacher(输出最长回文串及下标)
http://acm.hdu.edu.cn/showproblem.php?pid=3294 Girls' research Time Limit: 3000/1000 MS (Java/Others ...