2016 Multi-University Training Contest 1 Chess 组合游戏+状压(预处理)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5724
题意:一个n*20的棋盘,n <= 1000;棋盘上有一些棋子,每颗棋子只能移动到右边的第一个空格。不能移动者输;其中 Alice先手;如果Alice能赢输出"YES";
思路:每个子游戏的大小只有20,使用状压即可;但是每个子游戏的SG值需要建立在比其规模更小的SG值之上;这样,在二进制高位变为0低位变为1之后,显然数值变大了;
那么就二进制低位表示高位编码即可;
预处理出所有的有效状态的SG值之后,使用NIM和看ans 是否为0即可;为0表示先手输;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
#define MSi(a) memset(a,0x3f,sizeof(a))
#define inf 0x3f3f3f3f
#define A first
#define B second
#define MK make_pair
#define esp 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
#define bitnum(a) __builtin_popcount(a)
#define clear0 (0xFFFFFFFE)
#define mod 1000000007
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
template<typename T>
void read1(T &m)
{
T x = 0,f = 1;char ch = getchar();
while(ch <'0' || ch >'9'){ if(ch == '-') f = -1;ch=getchar(); }
while(ch >= '0' && ch <= '9'){ x = x*10 + ch - '0';ch = getchar(); }
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
template<typename T>
void out(T a)
{
if(a>9) out(a/10);
putchar(a%10+'0');
}
inline ll gcd(ll a,ll b){ return b == 0? a: gcd(b,a%b); }
int SG[1<<20], state[22];
void init()
{
for(int i = 0; i < 1<<20; i++){
MS0(state);
rep_1(j,19,0){
if(i & (1<<j)){
rep_1(k,j-1,0) if(!(i & (1 << k))){
state[SG[i^(1<<k)^(1<<j)]] = 1;
break;
}
}
}
rep1(j,0,19) if(state[j] == 0){
SG[i] = j;break;
}
}
}
int main()
{
//freopen("data.txt","r",stdin);
//freopen("out.txt","w",stdout);
init();
int T, kase = 1;
scanf("%d",&T);
while(T--){
int n, m, p, ans = 0;
read1(n);
rep1(i,1,n){
read1(m);
int S = 0;
while(m--){
read1(p);
S |= 1 << 20 - p;
}
ans ^= SG[S];
}
puts(ans?"YES":"NO");
}
return 0;
}
2016 Multi-University Training Contest 1 Chess 组合游戏+状压(预处理)的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 2016 Al-Baath University Training Camp Contest-1 E
Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 2016 Al-Baath University Training Camp Contest-1 J
Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...
- 2016 Al-Baath University Training Camp Contest-1 I
Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...
- 2016 Al-Baath University Training Camp Contest-1 H
Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...
- 2016 Al-Baath University Training Camp Contest-1 G
Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...
- 2016 Al-Baath University Training Camp Contest-1 F
Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...
- 2016 Al-Baath University Training Camp Contest-1 D
Description X is well known artist, no one knows the secrete behind the beautiful paintings of X exc ...
随机推荐
- Oracle基础 存储过程和游标
一.带游标的存储过程 游标作为参数有两种类型: 1.声明系统游标类型 SYS_REFCURSOR 1)游标作为存储过程的参数: --带游标的存储过程 CREATE OR REPLACE PROCEDU ...
- C++复习笔记
好多东西都忘了,现在重新复习一遍,把遇到的要点都记录下来.随时更新. 指针 C保证在为数组分配存储空间的时候,指向数组之后的第一个位置的指针也是合法的.也就是说保证指针 a + SIZE 是合法的,但 ...
- hdu 4494 最小费用流
思路:这题我在下午重现的时候就用的费用流做,可是各种悲催的超时,只是我一开始的那种建图方式多了一个二分查找. 戏剧性的是,求距离的返回值写成int型了,CodeBlock编译器又没有警告,然后就WA啊 ...
- 使用Boost asio实现同步的TCP/IP通信
可以先了解一下Boost asio基本概念,以下是Boost asio实现的同步TCP/IP通信: 服务器程序部分,如果想保留套接字之后继续通信,可以动态申请socket_type,保存指针,因为so ...
- Convert.ToInt32( null or "")
由于总忘记,先写一下. Console.WriteLine("输出转换空结果 ={0}", Convert.ToInt32("")); //Convert.To ...
- 递归小Demo
public class demo5 { public static void main(String[] args) { //初始值为100 int n = 100; ...
- JDBC学习笔记(一)
public static void main(String[] args) { ResultSet rs = null; Statement stmt = null; Connection conn ...
- (转)Android之常用功能方法大集合
这些,都是Andorid中比较常用的方法和功能,在网上搜集整理一下记录之,以备不时之需.由于经过多次转载,源文作者不确凿,在此申明,敬请见谅.不得不赞,非常实用. 1.判断sd卡是否存在 boolea ...
- 获取一年时间的sql
select a.day, to_char(a.day, 'day') as dd, 1 as flag,to_char(a.day,'YYYY-MM-DD') from ( SELECT TO_DA ...
- ReactiveCocoa比较区分replay, replayLast和replayLazily
一直搞不清楚replayLazily和replay的区别可以直接跳到最后看. 原文:http://spin.atomicobject.com/2014/06/29/replay-replaylast- ...