HDU 5724 Chess(SG函数)
Chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2605 Accepted Submission(s): 1092
The first line contains an integer T(T≤100)
, indicates the number of test cases.
For each test case, the first line contains a single integer n(n≤1000)
, the number of lines of chessboard.
Then n
lines, the first integer of ith line is m(m≤20)
, indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1≤pj≤20)
followed, the position of each chess.
1
2 19 20
2
1 19
1 18
YES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
int sg[(<<)+];
int main(){ for(int i = ;i < (<<); i++){
int h[];
memset(h, -, sizeof(h));
int last = -;
for(int j = ; j < ; j++){ if(!((i >> j) & ))
last = j;
if(((i >> j) & )){
if(last != -){
h[sg[(i ^ ( << j)) ^ ( << last)]]=;
}
}
}
int j=;
while(h[j] != -) j++;
sg[i]=j;
}
int T;
scanf("%d", &T);
while(T--){
int n, tmp, m, ans=;
scanf("%d", &n);
for(int i = ; i <= n; i++){
scanf("%d", &m);
tmp = ;
for(int j = ; j <= m; j++){
int x;
scanf("%d", &x);
tmp ^= << ( - x);
}
ans ^= sg[tmp]; }
if(ans)
puts("YES");
else
puts("NO");
}
}
HDU 5724 Chess(SG函数)的更多相关文章
- HDU 5742 Chess SG函数博弈
Chess Problem Description Alice and Bob are playing a special chess game on an n × 20 chessboard. ...
- HDU 5724 Chess(国际象棋)
HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- HDU 5724 Chess(SG函数+状态压缩)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...
- hdu 1848 简单SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...
- hdu 1809 求SG函数
A New Tetris Game(2) Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 5724 Chess (sg函数)
Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5724 Description Alice and Bob are playing a s ...
- HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场
题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...
- hdu 5724 Chess 博弈sg+状态压缩
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem De ...
随机推荐
- css用hover制作下拉菜单
首先我们的需求就是 制作一个鼠标移动到某个区域就会有下拉菜单的弹出,这样会有更多的子类内容,示例代码如下: <!DOCTYPE html> <html lang="en&q ...
- 使用 WireShark 分析 TCP/IP 三次握手 和 四次挥手
TCP 三次握手 示意图 Wireshark 抓包注意事项 为了演示一个TCP三次握手建立连接的过程,我们通过 Chrome 访问一个网页. 已知 HTTP 协议就是建立在TCP链接上的 比如访问以下 ...
- hdu 1712 (分组背包)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17676 这个问题让我对分组背包更清晰了一点,主要是这个问题: 使用一维数组的 ...
- 封装hiredis——C++与redis对接(一)(string的SET与GET操作)
在菜鸟教程自学了redis,总想着像Mysql一样,在C/C++中进行对接.于是查询了一些资料,最后找到了hiredis.然而直接用它的话,难免有点不方便.于是,对其进行封装. hiredis直接去g ...
- DOM节点常见的属性及操作
(1)常见节点属性 childNodes 子节点 nodeList children 子节点(元素节点) HTMLCollection parentNode 父节点 p ...
- ElementUI组件库常见方法及问题汇总(持续更新)
本文主要介绍在使用ElementUI组件库的时候,常遇见的问题及使用到的方法,汇总记录便于查找. 1.表单 阻止表单的默认提交 <!-- @submit.native.prevent --> ...
- js原生获取css属性
原文参考http://blog.csdn.net/lzding/article/details/46317777 1.写在dom上的属性,内联样式 <div id="box" ...
- mongodb添加登陆验证
mongodb添加登陆验证 转载地址 清空log,db目录 mongod --auth --logpath "D:\mongodb\log\log.log" --logappend ...
- 【Python】raw转义字符
r"hi" 这里字符串前面加了r,是raw的意思,它表示对字符串不进行转义.为什么要加这个?你可以试试print "\bhi"和r"\bhi" ...
- jdk1.8 对数组及arrays类对数组的操作与增强
数组的初始化有两种方式 静态初始化: 初始化时由程序员显示置顶每个数组的初始值,由系统决定数组长度.如: int[] a1 = new int[] {1,2,3,4}; 动态初始化:初始化时由程序员只 ...