Chess

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1821    Accepted Submission(s): 799

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
/*
hdu 5724 SG+状态压缩 感觉上是博弈,而且很久以前就看了看SG,但是并没怎么系统地去学习zzz。
首先可以把棋盘n行看成n个石碓,用1表示有棋子,0表示没有的话,能够用二进制表示出所有的状态:
1000100这个可以转换成 0100100 1000010等等 然后就能利用公式求出每种情况的SG(枚举 1~(1<<20))
得出每一行的状态计算即可 hhh-2016-08-01 17:28:17
学习:
//http://blog.csdn.net/luomingjun12315/article/details/45555495
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const int maxn = 1000100; int vis[22];
int sg[1<<20]; int SG(int cur)
{
memset(vis,0,sizeof(vis));
for(int i = 20; i >= 0; i--)
{
if(cur & (1<<i))
{
for(int j = i-1; j >= 0; j--)
{
if(!(cur & (1 << j)))
{
int tmp = cur;
tmp ^= ((1<<i)^(1<<j));
vis[sg[tmp]] = true;
break;
}
}
}
}
for(int i = 0 ; i <= 20; i++)
{
if(!vis[i])
return i;
}
return 0;
} int main()
{
memset(sg,0,sizeof(sg));
for(int i = 1; i < (1 << 20); i++)
sg[i] = SG(i);
int T,n,x;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int ans = 0;
for(int i = 1;i <= n;i++)
{
int m,cur = 0;
scanf("%d",&m);
for(int j = 1;j <= m;j++)
{
scanf("%d",&x);
cur |= 1 << (20-x);
}
ans ^= sg[cur];
}
if(ans )
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

  

hdu 5724 SG+状态压缩的更多相关文章

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

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

  2. hdu 5094 Maze 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...

  3. hdu 4272 LianLianKan 状态压缩

      LianLianKan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. hdu 1429(bfs+状态压缩)

    题意:容易理解,但要注意的地方是:如果魔王回来的时候刚好走到出口或还未到出口都算逃亡失败.因为这里我贡献了一次wa. 分析:仔细阅读题目之后,会发现最多的钥匙数量为10把,所以把这个作为题目的突破口, ...

  5. hdu 2489 最小生成树状态压缩枚举

    思路: 直接状态压缩暴力枚举 #include<iostream> #include<algorithm> #include<cstdio> #include< ...

  6. LianLianKan - HDU 4272(状态压缩)

    题目大意:有一列数据,可以从最上面的开始连接下面相同的元素,然后消除,不过距离不能超过6,询问最后能不能消除完整个数列. 分析:首先讨论一点最远能消除的地方,比如点的位置是x,如若想要消除x+1位置处 ...

  7. HDU 3001(状态压缩dp)

    状态压缩dp的第一题! 题意:Mr ACMer想要进行一次旅行,他决定访问n座城市.Mr ACMer 可以从任意城市出发,必须访问所有的城市至少一次,并且任何一个城市访问的次数不能超过2次.n座城市间 ...

  8. hdu 4856 Tunnels 状态压缩dp

    Tunnels Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem ...

  9. HDU 1074 (DP + 状态压缩)

    题意: 给你N个课程, 每个课程有结束的时间 , 和完成这门课程需要的时间 超过课程结束ed时间,每一天就要花费 1点绩点: 然后要求你安排如何做课程使得花费的绩点最少 (看了博客后才发现状态压缩很⑥ ...

随机推荐

  1. beta版本复审

    C++team复审 小组 优点 缺点 打分 MyGod小组 MyGod团队开发了一个让武汉大学的学生能够方便地了解校内二手物品交易信息,并进行相应的交易的安卓app.出发点不错,有创新点.使用了一下他 ...

  2. python pdb 调试

    命令行 Python -m pdb xxx.py l ----> list 显示当前代码 n ----> next 向下执行一行代码 c ----> continue 继续执行代码 ...

  3. io多路复用(三)

    #!/usr/bin/env python # -*- coding:utf-8 -*- import socket sk1 = socket.socket() sk1.bind(('127.0.0. ...

  4. python多目录字符串查找匹配

    1. 需求来自于实际工作: 需要处理一批服务器上运行的redis实例,每个redis实例可能有密码,也可能没有,有密码的,密码配置格式一定是: requirepass XXXXX # XXXX是密码 ...

  5. c语言中宏定义和常量定义的区别

    他们有共同的好处就是"一改全改,避免输入错误"哪两者有不同之处吗?有的. 主要区别就在于,宏定义是在编译之前进行的,而const是在编译阶段处理的 宏定义不占用内存单元而const ...

  6. 用C#(.NET Core) 实现简单工厂和工厂方法模式

    本文源自深入浅出设计模式. 只不过我是使用C#/.NET Core实现的例子. 前言 当你看见new这个关键字的时候, 就应该想到它是具体的实现. 这就是一个具体的类, 为了更灵活, 我们应该使用的是 ...

  7. C#实现导出Excel

    这段时间用到了导出Excel的功能,这个功能还是比较常用的,我常用的有两个方法,现在整理一下,方便以后查看. 一.实现DataTable数据导出到本地,需要自己传进去导出的路径. /// <su ...

  8. DevExpress控件的GridControl实现行多选

    最近用到DevExpress控件的GridControl控件,需要用到行多选的操作,在网上找的资料,自己总结一下. 先展示一下效果:

  9. Linux命令(持续更新中)

    命令名 用法 安装上传下载 yum install lrzsz   rz上传文件,sz下载文件 压缩 解压文件 tar -zxvf  文件名 压缩文件 tar -zcvf 文件名 删除非空目录: rm ...

  10. Tess4J OCR简单使用教程

    Tess4J简介 Tesseract-OCR支持中文识别,并且开源和提供全套的训练工具,是快速低成本开发的首选.而Tess4J则是Tesseract在Java PC上的应用.在英文和数字识别中性能还是 ...