Chess

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的棋盘
  每一行有若干棋子,A,B轮流移动棋子,每次可以选定一个棋子移动到右边第一个空格,直到不能移动的人败
题解:
  SG
  吧SG(1<<20)的状态全部预处理出来就可以了
  再把sg值全部异或起来,为0先手输
#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函数博弈的更多相关文章

  1. 博弈问题之SG函数博弈小结

    SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Ga ...

  2. hdu 1848 简单SG函数

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

  3. SG函数博弈——poj2311

    关于SG函数的博弈 首先定义必败态 x : SG[x]=0 设任意一个状态y,到所有y能到达的状态连一条边,令这些后继为z y : SG[y]=mex(SG[z]) SG[y]==0 : y就是必败态 ...

  4. hdu 1809 求SG函数

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

  5. HDU1536&&POJ2960 S-Nim(SG函数博弈)

    S-Nim Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status ...

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

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

  7. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  8. HDU 1848 SG函数博弈

    Fibonacci again and again Problem Description   任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1 ...

  9. 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 ...

随机推荐

  1. npm 发布到远程资源库

    一.npm 发布到远程资源库 1.创建package.json Package.json 属性说明 name - 包名. version - 包的版本号. description - 包的描述. ho ...

  2. Node.js API 初解读(二)

    四. Cluster 1.简介 在介绍 Cluster 之前.我们需要知道 node的 一些基本特性,比如说 都知道的 nodejs最大的特点就是单进程.无阻塞运行,并且是异步事件驱动的. 那么随之而 ...

  3. 【转】MySQL性能优化的最佳21条经验

    文章转自: http://blog.csdn.net/waferleo/article/details/7179009 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关 ...

  4. 调用WebServices超时

    1. 服务器端设置超时 在 web.config 的 system.web 里添加如下配置项: < httpRuntimeexecutionTimeout="300000"/ ...

  5. 如何删除已安装的Windows服务

    1) 开始-运行,输入regedit命令.  (Windows键+R,输入regdeit) 2) 回车后会弹出一个窗口:注册编辑器.找到 HKEY_LOCAL_MACHINE\SYSTEM\Curre ...

  6. VS2010+Qt5.4.0 环境搭建(离线安装)

    原创作者:http://blog.csdn.net/solomon1558/article/details/44084969 前言 因项目需要Qt开发GUI,我根据网上资料及自己的经验整理了搭建vs2 ...

  7. windows XP上实现python2.7.5和python3.4.3共存

    windows XP上实现python2.7.5和python3.4.3共存过程记录: 1. 首先安装python2.7.5和python3.4.3,两个版本安装顺序不分前后; 2. 检查系统环境变量 ...

  8. JS学习:第一周——NO.4继承

    1.[关于call] 作用:是用来改变this指向的,有两种参数 第一种:第一个参数,用来改变this指向 第二种:给call前面的函数传参,从第二个参数开始,给call前面的函数从左到右一个个的传参 ...

  9. linux几个常用的命令及获取帮助的方法

    date:时间管理,可以显示.修改系统时间.  设定时间:格式:MMDDhhmm[[cc]yy][.ss]其中MM为月分,DD为日期,hh为小时,mm为分钟,CC为年的前两位 YY为年分的后两位,.s ...

  10. eclipse中ctrl+h默认打开是JavaSearch,怎么设置成默认打开是FileSearch

    window->preferences->General->keys. 找到File Search(有搜索框的,可以搜索),然后在下方 Binding按下ctrl +h .