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函数的更多相关文章

  1. 洛谷P2575高手过招——SG函数初试

    题目:https://www.luogu.org/problemnew/show/P2575 第一次用SG函数解决问题,有许多不熟练的地方: 试图按自己的理解写一个dfs,结果错了(连题都没读对,以为 ...

  2. 洛谷$P$2575 高手过招 博弈论

    正解:博弈论 解题报告: 传送门! 阿西$gql$又双叒被题意杀辣,,,再不好好学语文吃枣药丸$TT$ 然后在$get$规则之后还有什么问题嘛,,, 就和这题差不多了,一个$easy$的阶梯问题罢辽, ...

  3. Luogu P2575 高手过招

    题目链接 \(Click\) \(Here\) 关键在于转换成阶梯\(Nim\)的模型.最开始把题目看错了,理解正确后发现棋子可以向后跳不止一位,那么就比较简单了. 这里把空格看做阶梯,棋子看做硬币, ...

  4. BZOJ 1188 / Luogu P3185 [HNOI2007]分裂游戏 (SG函数)

    题意 有n个格子,标号为0 ~ n-1,每个格子上有若干石子,每次操作可以选一个0 ~ n-2的格子上的一颗石子,分裂为两颗,然后任意放在后面的两个格子内,这两个格子可以相同.求使先手必胜的第一步的方 ...

  5. 博弈论与SG函数

    巴什博奕: 两个顶尖聪明的人在玩游戏,有n个石子,每人可以随便拿1−m个石子,不能拿的人为败者,问谁会胜利 结论: 设当前的石子数为\(n=k∗(m+1)\)即\(n%(m+1)==0\)时先手一定失 ...

  6. P3235-[HNOI2014]江南乐【整除分块,SG函数】

    正题 题目链接:https://www.luogu.com.cn/problem/P3235 题目大意 \(T\)组游戏,固定给出\(F\).每组游戏有\(n\)个石头,每次操作的人可以选择一个数量不 ...

  7. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  8. 【转】博弈—SG函数

    转自:http://chensmiles.blog.163.com/blog/static/12146399120104644141326/ http://blog.csdn.net/xiaofeng ...

  9. 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)运算 ...

随机推荐

  1. mysql攻防之写入漏洞

    因为被别人利用mysql攻击,所以想在这里帮助大家提高一下自身mysql的安全.避免成为别人的肉鸡. show global variables like '%secure%'; 如果是这样则黑客可以 ...

  2. python学习day4 数据类型 if语句

    1.变量的内存管理 cpython解释器垃圾回收机制 什么是垃圾,当一个值身上没有绑定变量名时,(该值的引用计数=0时)就是一个垃圾 age=18 #18的引用计数=1 x=age  #18的引用计数 ...

  3. Spring知识结构

    课程目标:          1. 回顾                    * 传统的开发模式                    * Struts与Hibernate可以做什么事?       ...

  4. oracle wm_concat() 返回空

    参考 https://www.cnblogs.com/zengweiming/archive/2013/11/20/3433642.html select wm_concat(to_char(str) ...

  5. TOJ 2755 国际象棋(搜索)

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=2755 思路:对起点到终点进行广搜, ...

  6. 22. Generate Parentheses (backTracking)

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  7. 转:WCAT 压力工具介绍

    原文地址:http://blogs.msdn.com/alikl/archive/2008/03/09/stress-test-asp-net-web-application-with-free-wc ...

  8. Mac 上fopen总返回NULL

    全局,相对路径都不行, 在沙盒中获取也不行 //在沙盒中获取Documents的完整路径 NSString * path = [NSSearchPathForDirectoriesInDomains( ...

  9. f5 SNAT

    request过程: 1.真实源地址(3.3.3.3)将数据包发给f5虚拟的vs地址(1.1.1.5:80): 2.f5将真实源地址(3.3.3.3)转换成SNAT地址(1.1.1.100),并将vs ...

  10. Springboot学习03-SpringMVC自动配置

    Springboot学习03-SpringMVC自动配置 前言 在SpringBoot官网对于SpringMVCde 自动配置介绍 1-原文介绍如下: Spring MVC Auto-configur ...