Chess

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

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
 
解题思路:
  此题相较一般的组合博弈规则上有所不同,无法使用一般的Nim博弈、威佐夫博弈那样直接用公式进行推导而取得结果,所以一般使用SG函数来处理此类问题,而此题由于状态相对单一(即一个点只有有棋子和没有棋子两种状态),故可用一bit来表示在一行中一个点有没有棋子,有棋子为1,没有棋子为0,因为每一行的棋子数量不定,故有可能一行20个位置都是棋子为了表示这种的不同的情况,进行状态压缩,用一个int来表示这种情况显然是更好的选择。其中int i=1即代表一行只有一个棋子,而此棋子在最右边的情况,0到(2^20-1)就代表全了所有的可能,存于SG中,之后读取并Nim博弈的异或看结果就好了。
 
代码:
 #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函数)的更多相关文章

  1. HDU 5742 Chess SG函数博弈

    Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. ...

  2. HDU 5724 Chess(国际象棋)

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

  3. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

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

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

  5. hdu 1848 简单SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...

  6. hdu 1809 求SG函数

    A New Tetris Game(2) Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. HDU 5724 Chess (sg函数)

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

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

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

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

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

随机推荐

  1. Android和kernel杂散点集合

    Android: 1.编译 普通的编译: 1). source build/envsetup.sh 2).lunch 3).make -jx make kernel:只重新编译kernel部分镜像,但 ...

  2. sleep函数作用(转)

    表示当前线程暂时不参与cpu竞争,该函数会阻塞方法,一般在比较耗时的任务中执行了一段时间后会调用一下该方法避免当前任务一直霸占cpu,详情可以查看以下参考链接. 我们可能经常会用到 Thread.Sl ...

  3. vue 报错./lib/html5-entities.js, this relative module was not found

    今天在做项目一直都挺正常的,我稍微休息一下回来就报这个错,我百度了半天也没找到答案.然后我只能重新安装vue-cli,奇迹发生了错误没有,然后我又休息了一会发现有报错了.气炸了都. 话不多多说直接上图 ...

  4. PHP学习9——MySQL数据库

    主要内容: MySQL的启动 MySQL数据库操作 数据库表设计 创建和查看表 修改表结构 MySQL语句操作 数据库备份与恢复 PHP操作MySQL数据库 面向对象的数据库操作 MySQL数据库是目 ...

  5. C#实现Javascript的Splice方法

    最近开始学习Javascript语言,看到splice方法,以下引用其说明:该方法是一个通用删除和插入元素的方法,它可以在数组指定的位置开始删除或插入元素.其包括3个参数:第一个参数指定插入的起始位置 ...

  6. 2.VS2012为创建的类添加注释的模板

    在项目中给类添加注释的优点: 1.方便查看这个类是为了那些功能 2.是成员小组中的谁负责编写的 根据自己的vs的安装路径找到类模板的位置:D:\Program Files (x86)\Microsof ...

  7. Angular4 step by step.1

    1.官网地址 :https://angular.cn/guide/quickstart 2.在线学习地址:https://embed.plnkr.co/?show=preview 3.效果截图哇哈哈

  8. springboot自定义异常

    SpringBoot自定义异常以及异常处理 在web项目中,我们可能需要给前端返回不同的提示码.例如:401表示没有权限,500代表位置异常,200代表请求成功等.但是这些提示码远远不能满足我们返回给 ...

  9. WebClient用法小结(转载)

    如果只想从特定的URI请求文件,则使用WebClient,它是最简单的.NET类,它只用一两条命令执行基本操作,.NET FRAMEWORK目前支持以http:.https:.ftp:.和 file: ...

  10. ArcGIS DataStore手册——管理篇

    第二章:ArcGIS DataStore管理维护 1.备份管理 备份的目的在于发生原始数据损坏或其他突发情况时,可避免数据丢失,并可快速的使用备份数据来恢复,以保证服务仍可使用. 单机模式下,可使用D ...