Chess

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the moved chess, move the chess to its right adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. Two chesses can’t be placed at one block and no chess can be placed out of the chessboard. When someone can’t move any chess during his/her turn, he/she will lose the game. Alice always take the first turn. Both Alice and Bob will play the game with the best strategy. Alice wants to know if she can win the game.
 
Input
Multiple test cases.

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.

 
Output
For each test case, output one line of “YES” if Alice can win the game, “NO” otherwise.
 
Sample Input
2
1
2 19 20
2
1 19
1 18
 
Sample Output
NO
YES
 
Author
HIT
 
Source
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define LL __int64
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=3e6+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; int sg[N];
int dfs(int n)
{
if(sg[n]!=-)return sg[n];
int flag[],nex[], mex[];
for(int i=;i<;i++)
flag[i]=,mex[i]=,nex[i]=;Q
for(int i=;i<;i++)
if(n&(<<i))flag[i]=;
nex[]=;
for(int i=;i>=;i--)
if(!flag[i+])nex[i]=i+;
else nex[i]=nex[i+];
for(int i=;i<;i++)
{
if(flag[i]&&nex[i]<)
{
int z=n-(<<i)+(<<nex[i]);
//cout<<z<<endl;
dfs(z);
mex[sg[z]]=;
}
}
for(int i=;;i++)
if(!mex[i])return sg[n]=i;
}
int main()
{ memset(sg,-,sizeof(sg));
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int ans=;
for(int i=;i<=n;i++)
{
int m,sum=;
scanf("%d",&m);
for(int j=;j<=m;j++)
{
int x;
scanf("%d",&x);x--;
sum+=(<<x);
}
ans^=dfs(sum);
}
if(ans)printf("YES\n");
else printf("NO\n");
}
return ;
}

hdu 5724 Chess 博弈sg+状态压缩的更多相关文章

  1. HDU 5724 Chess(SG函数+状态压缩)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...

  2. HDU 5724 Chess (sg函数)

    Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5724 Description Alice and Bob are playing a s ...

  3. HDU 5724 Chess(SG函数)

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  4. hdu 5724 Chess 博弈

    题目链接 一个n行20列的棋盘. 每一行有若干个棋子. 两人轮流操作, 每人每次可以将一个棋子向右移动一个位置, 如果它右边有一个棋子, 就跳过这个棋子, 如果有若干个棋子, 就将这若干个都跳过. 但 ...

  5. hdu 5724 SG+状态压缩

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  6. HDU 5724 Chess(国际象棋)

    HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  7. hdu 5025 Saving Tang Monk 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...

  8. HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场

    题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...

  9. HDU 5724 Chess(博弈论)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5724 [题目大意] 给出一个n行,每行有20格的棋盘,棋盘上有一些棋子,每次操作可以选择其中一个棋 ...

随机推荐

  1. AtCoder Beginner Contest 087 (ABC)

    A - Buying Sweets 题目链接:https://abc087.contest.atcoder.jp/tasks/abc087_a Time limit : 2sec / Memory l ...

  2. centos6使用yum安装python3和pip3

    在安装了epel源的情况下,直接yum就可以安装python3.4 #yum install python34 -y# python3 --versionPython 3.4.5 没有自带pip3,需 ...

  3. P1012 拼数

    P1012 拼数 输入输出样例 输入样例 3 13 312 343 输出样例 34331213 注意 当你输入: 6321 32 407 135 13 217 应该输出: 40732321217135 ...

  4. Tensorflow timeline trace

    根据 https://github.com/tensorflow/tensorflow/issues/1824 简单进行了测试 修改运行的脚本增加如下关键代码 例如mnist_softmax.py f ...

  5. 监控网卡流量脚本(Python)

    #!/usr/bin/env python# coding: utf-8# author: Xiao Guaishou try:    import psutilexcept ImportError: ...

  6. 利用yum搭建lamp环境并进一步创建博客

    用yum搭建lamp环境 第一.安装apache yum -y install httpd 第二.安装mariadb Yum -y mariadb mariadb-server 第三.安装php Yu ...

  7. Java 安全套接字编程以及keytool 使用最佳实践

    概述 利用 Java 的 JSSE(Java Secure Socket Extension)技术,我们可以方便的编写安全套接字程序,关于 JSSE 的介绍,可以参阅 Oracle 网站提供的 JSS ...

  8. fjwc2019 D3T2 送分题

    #185. 「2019冬令营提高组」送分题 这是原题..... P3615 如厕计划 手推一推你发现,显然男性不能多于女性. 然后你或许可以发现一个神奇的性质. 对于每个序列,我们记$M$为$1$,$ ...

  9. 05: greenlet:轻量级的并发编程

    网络编程其他篇 1.1 greenlet简介 1.greenlet原理 & 使用 1. greenle间切换 1)一个 “greenlet” 是一个很小的独立微线程,可以把它想像成一个堆栈帧, ...

  10. UVa 11997 K Smallest Sums - 优先队列

    题目大意 有k个长度为k的数组,从每个数组中选出1个数,再把这k个数进行求和,问在所有的这些和中,最小的前k个和. 考虑将前i个数组合并,保留前k个和.然后考虑将第(i + 1)个数组和它合并,保留前 ...