HDU 5742 Chess SG函数博弈
Chess
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 <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = 5e5+, M = 2e5+, mod = 1e9+, inf = 2e9; int sg[<<],vis[];
void init() {
int NN = <<;
for(int i = NN; i >= ; --i) {
memset(vis,,sizeof(vis));
int last = -;
for(int j = ; j >= ; --j) {
if((i&(<<j)) == ) last = j;
else {
if(last == -) continue;
int now = i - (<<j) + (<<last);
vis[sg[now]] = ;
}
}
for(int j = ; j <= ; ++j) {
if(!vis[j]) {
sg[i] = j;
break;
}
}
}
}
int main() {
init();
int T,m,x,y;
scanf("%d",&T);
while(T--) {
scanf("%d",&m);
int ans = ;
for(int i = ; i <= m; ++i) {
int now = ;
scanf("%d",&x);
while(x--) {
scanf("%d",&y);
y--;
now += (<<(y));
}
ans ^= sg[now];
}
if(ans) puts("YES");
else puts("NO");
}
return ;
}
HDU 5742 Chess SG函数博弈的更多相关文章
- 博弈问题之SG函数博弈小结
SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Ga ...
- hdu 1848 简单SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...
- SG函数博弈——poj2311
关于SG函数的博弈 首先定义必败态 x : SG[x]=0 设任意一个状态y,到所有y能到达的状态连一条边,令这些后继为z y : SG[y]=mex(SG[z]) SG[y]==0 : y就是必败态 ...
- hdu 1809 求SG函数
A New Tetris Game(2) Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU1536&&POJ2960 S-Nim(SG函数博弈)
S-Nim Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit Status ...
- HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场
题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 1848 SG函数博弈
Fibonacci again and again Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1 ...
- hdu 4388 Stone Game II sg函数 博弈
Stone Game II comes. It needs two players to play this game. There are some piles of stones on the d ...
随机推荐
- #pragma once与#ifndef #define ...#endif的区别
1. #pragma once用来防止某个头文件被多次include: #ifndef,#define,#endif用来防止某个宏被多次定义. 2. #pragma once是编译相关,就是说这个 ...
- js计时器,点击开始计时,再点击停止
点击倒计时开始,点击停止,再次点击又开始,再点停止... <i id=</i>秒 <em onclick="timeOpen();">开始</e ...
- Tomcat性能优化
1.关闭AJP协议 注释以下配置 <!-- <Connector port="8009" protocol="AJP/1.3" redirectPo ...
- 【04-10】java中的路径
java中的路径 System.getProperty("user.dir") 获取工程的绝对路径 Class.class.getClass().getResource(&quo ...
- RabbitMQ常用命令行
打印了一些rabbitmq服务状态信息,包括内存,硬盘,和使用erlong的版本信息rabbitmqctl -q status 各个参数说明:http://www.rabbitmq.com/man/r ...
- controller_name classify constantize model_name
控制器 class CourseSurveysController < ResourcesBaseController end controller_name # "course_su ...
- HDU4329
#include<cstdio> #include<algorithm> #include<map> using namespace std; int main() ...
- libvirt 安装篇
1. 环境:Centos 7 python 2.7 2. 安装 sudo yum install gcc python-devel libvirt libvirt-devel sudo ...
- python之路十九
1.Django请求生命周期 -> URL对应关系(匹配) -> 视图函数 -> 返回用户字符串 -> URL对应关系(匹配) -> 视图函数 ...
- docker 目录迁移
(ubuntu 12.04) 默认路径 /var/lib/docker --> /data/docker root@node1:~# service docker stop root@node ...