Luogu 2575 高手过招-SG函数
Solution
SG函数跑一遍就过了ouo
Code
#include<cstring>
#include<cstdio>
#include<algorithm>
#define rd read()
#define cl(a) memset(a, 0, sizeof(a));
using namespace std; const int N = << ; int SG[N], S[];
int T, n; int read() {
int X = , p = ; char c = getchar();
for(; c > '' || c < ''; c = getchar()) if(c == '-') p = -;
for(; c >= '' && c <= ''; c = getchar()) X = X * + c - '';
return X * p;
} void mkSG() {
for(int i = ; i < ; ++i) SG[i] = ;
for(int i = ; i < ( << ); ++i) {
cl(S);
int last = -, nt;
for(int j = ; j < ; ++j) if((i >> j) & ) {
if(~last) {
nt = i | ( << last);
nt ^= << j;
S[SG[nt]] = ;
}
} else last = j;
int j = ;
for(; S[j]; ++j);
SG[i] = j;
}
} int main()
{
mkSG();
T = rd;
for(; T; T--) {
n = rd;
int ans = ;
for(int i = ; i <= n; ++i) {
int m = rd, tmp = ;
for(int j = ; j <= m; ++j) {
int x = rd;
tmp |= << ( - x);
}
ans ^= SG[tmp];
}
if(ans) puts("YES");
else puts("NO");
}
}
Luogu 2575 高手过招-SG函数的更多相关文章
- 洛谷P2575高手过招——SG函数初试
题目:https://www.luogu.org/problemnew/show/P2575 第一次用SG函数解决问题,有许多不熟练的地方: 试图按自己的理解写一个dfs,结果错了(连题都没读对,以为 ...
- 洛谷$P$2575 高手过招 博弈论
正解:博弈论 解题报告: 传送门! 阿西$gql$又双叒被题意杀辣,,,再不好好学语文吃枣药丸$TT$ 然后在$get$规则之后还有什么问题嘛,,, 就和这题差不多了,一个$easy$的阶梯问题罢辽, ...
- Luogu P2575 高手过招
题目链接 \(Click\) \(Here\) 关键在于转换成阶梯\(Nim\)的模型.最开始把题目看错了,理解正确后发现棋子可以向后跳不止一位,那么就比较简单了. 这里把空格看做阶梯,棋子看做硬币, ...
- BZOJ 1188 / Luogu P3185 [HNOI2007]分裂游戏 (SG函数)
题意 有n个格子,标号为0 ~ n-1,每个格子上有若干石子,每次操作可以选一个0 ~ n-2的格子上的一颗石子,分裂为两颗,然后任意放在后面的两个格子内,这两个格子可以相同.求使先手必胜的第一步的方 ...
- 博弈论与SG函数
巴什博奕: 两个顶尖聪明的人在玩游戏,有n个石子,每人可以随便拿1−m个石子,不能拿的人为败者,问谁会胜利 结论: 设当前的石子数为\(n=k∗(m+1)\)即\(n%(m+1)==0\)时先手一定失 ...
- P3235-[HNOI2014]江南乐【整除分块,SG函数】
正题 题目链接:https://www.luogu.com.cn/problem/P3235 题目大意 \(T\)组游戏,固定给出\(F\).每组游戏有\(n\)个石头,每次操作的人可以选择一个数量不 ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- 【转】博弈—SG函数
转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...
- HDU 1848 Fibonacci again and again【SG函数】
对于Nim博弈,任何奇异局势(a,b,c)都有a^b^c=0. 延伸: 任何奇异局势(a1, a2,… an)都满足 a1^a2^…^an=0 首先定义mex(minimal excludant)运算 ...
随机推荐
- CentOS6.5安装MySQL5.7详细教程(本人6.3也行)
本文参考http://www.cnblogs.com/lzj0218/p/5724446.html 主要参考博文: https://segmentfault.com/a/119000000304949 ...
- MVC003之调用BLL层方法(BLL层调用了WebService)
项目又BLL类库,在类库中引用了webservice.在web层调用BLL的方法时 错误如下: 在 ServiceModel 客户端配置部分中,找不到引用协定“OAService.IntranetSe ...
- dedecms(织梦系统)如何更新手机版首页模板文件
https://jingyan.baidu.com/article/ad310e80e4b1dd1849f49e8f.html
- 二进制中1的个数(python)
题目描述 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. # -*- coding:utf-8 -*- class Solution: def NumberOf1(self, n): ...
- 牛客练习赛43-F(简单容斥)
题目链接:https://ac.nowcoder.com/acm/contest/548/F 题意:简化题意之后就是求[1,n]中不能被[2,m]中的数整除的数的个数. 思路:简单容斥题,求[1,n] ...
- 二叉树的深度优先遍历与广度优先遍历 [ C++ 实现 ]
深度优先搜索算法(Depth First Search),是搜索算法的一种.是沿着树的深度遍历树的节点,尽可能深的搜索树的分支. 当节点v的所有边都己被探寻过,搜索将回溯到发现节点v的那条边的起始节点 ...
- TOJ4127: Root of String
传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=4127 4127: Root of ...
- 线程 Thread Handler
new Thread(new Runnable() { @Override public void run() { Message msg = new Message(); msg.what = 0; ...
- android.support.v4与Android.support.v7
Android提供了android.support.v4和android.support.v7两个库,以便低版本API可以使用高版本API的功能. Fragment(碎片)类,是在Android 3. ...
- React学习札记一
I’m in a hurry! 我在赶时间! It’s her field. 这是她的本行. It’s up to you. 由你决定. You owe me one.你欠我一个人情. 1.React ...