题目链接:

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
 
题意:
 
给一个n*20的棋盘,每行的一部分格子里面有棋子,现在每次可以选一个棋子把它挪到右边第一个空位上;现在问先手是否能必胜;
思路:
组合博弈的内容,先处理出所有状态的sg函数值,然后取异或值判断是否为零;
 
AC代码:
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
//#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=2e6+10;
const int maxn=500+10;
const double eps=1e-8; int sg[N],vis[25]; inline int get_sg(int x)
{
mst(vis,0);
//cout<<x<<endl;
for(int i=19;i>=0;i--)
{
if(x&(1<<i))
{
int temp=x;
for(int j=i-1;j>=0;j--)
{
if(!(x&(1<<j)))
{
temp^=(1<<i)^(1<<j);
//cout<<temp<<endl;
vis[sg[temp]]=1;
break;
}
}
}
}
for(int i=0;i<=19;i++)if(!vis[i])return i;
return 0;
}
inline void Init()
{
For(i,0,(1<<20)-1)sg[i]=get_sg(i);
}
int main()
{
Init();
int t;
read(t);
while(t--)
{
int n,a,m,ans=0;
read(n);
while(n--)
{
int sum=0;
read(m);
For(i,1,m)
{
read(a);
sum|=(1<<(20-a));
}
ans^=sg[sum];
}
if(ans)printf("YES\n");
else printf("NO\n");
} return 0;
}

  

 

hdu-5724 Chess(组合游戏)的更多相关文章

  1. HDU 5724 Chess(国际象棋)

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

  2. HDU 1536 S-Nim (组合游戏+SG函数)

    题意:针对Nim博弈,给定上一个集合,然后下面有 m 个询问,每个询问有 x 堆石子 ,问你每次只能从某一个堆中取出 y 个石子,并且这个 y 必须属于给定的集合,问你先手胜还是负. 析:一个很简单的 ...

  3. 2016 Multi-University Training Contest 1 Chess 组合游戏+状压(预处理)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5724 题意:一个n*20的棋盘,n <= 1000;棋盘上有一些棋子,每颗棋子只能移动到右边的第一个 ...

  4. HDU 5724 Chess (sg函数)

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

  5. HDU 5724 Chess(博弈论)

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

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

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

  7. HDU 5724 Chess(SG函数)

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

  8. hdu 5724 Chess 博弈sg+状态压缩

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

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

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

随机推荐

  1. 【jQuery】input textarea 文本变化的动态监听

    实时监听Input textarea文本变化的监听事件:[但不包含通过js动态添加改变的文本事件] HTML: <textarea style="display: none" ...

  2. Android开发者选项——Gpu呈现模式分析

    对于Android用户来说,无论你用的什么品牌的手机,在开发者选项中都能发现“玄学曲线”的开关,之所以称其为玄学曲线,还是因为它被很多网友用于测试一个说不清道不明的东西——流畅度.到底多流畅才叫流畅, ...

  3. mac git安装及github配置

    准备下载一个react的demo程序包,需要本地用到git.早就向配置了,那就安装配置一下吧. 首先,原来mac已经安装了git,版本 2.7 ,我用 brew又安装了一份git 版本 2.10.2. ...

  4. sql的一些知识_高级

    1.视图 http://www.cnblogs.com/wang666/p/7885934.html 2.存储过程 http://www.cnblogs.com/wang666/p/7920748.h ...

  5. meta标签多种用法

    <meta name=”google” content=”notranslate” /> <!-- 有时,Google在结果页面会提供一个翻译链接,但有时候你不希望出现这个链接,你可 ...

  6. Tessellation (曲面细分) Displacement Mapping (贴图置换)

    DirectX 11 Tessellation (曲面细分)-什么是 Tessellation (曲面细分) ? 它为什么可以起到如此关键的数据? 随着近期人们对 DirectX 11 的议论纷纷,你 ...

  7. 【每日Scrum】第六天(4.27) TD学生助手Sprint2站立会议

    站立会议 组员 昨天 今天 困难 签到 刘铸辉 (组长) 今天和楠哥做了课程事件和日历表操作的例子,并尝试做时间表和日历表的数据库设计 Y 刘静 今天开始编辑自己项目中的日历管理 编辑程序,能够在日历 ...

  8. ORCAD元件属性白色区域和黄色区域的理解

    白色部分为instance属性,黄色部分为occurence 属性 在平坦式电路中,黄色部分是默认不显示的. 在层次式电路中,黄色部分会显示.      如果这两个区域的Reference不同,以黄色 ...

  9. Canvas学习笔记——弹动

    如果有一根橡皮筋拴住一个小球,将小球拉开一定距离后释放,小球将会弹动.距离越远,橡皮筋对小球施加的外力越大,小球的加速度就越大.也就是说,小球的加速度与距离是成正比例关系的.这和缓动很相似,缓动是速度 ...

  10. 第 2 章 第 1 题 同位词问题 下问 Multimap实现

    问题分析 输入:一个任意的单词和一个内含多个乱序单词的字典文件 输出:该单词在字典中的所有同位词 约束:允许事先对字典进行预处理 解决思路 上问的程序有个缺点 - 我们必须遍历完整个字典文件才能输出所 ...