2016多校联合训练1 B题Chess (博弈论 SG函数)

题目大意:一个n(n<=1000)行,20列的棋盘上有一些棋子,两个人下棋,每回合可以把任意一个棋子向右移动到这一行的离这个棋子最近的空格上(注意这里不一定是移动最后一个棋子),不能移动到棋盘外,不能移动了就算输,两个人都用最优策略,问先手是否有必胜策略。

这题显然就是SG函数了吧。行与行之间互不影响,所以可以看成n个子游戏,求出它们各自的SG函数然后异或一下就可以了。我们发现只有20列,2^21=2097152,所以我们可以先把行的所有情况的SG函数预处理出来,然后每次询问O(1)就行了。

代码如下:

var
  t,i,j,m,v,c,res,n,cl:longint;
  cnt:array[0..22]of longint;
  a:array[0..10000000]of longint;

procedure calc(x,c:longint);
begin
  dec(x,1<<(c-1));inc(c);
  while c<=20 do
  begin
    if x and (1<<(c-1))=0 then break;
    inc(c);
  end;
  if c>20 then exit;
  inc(x,1<<(c-1));
  cnt[a[x]]:=1;
end;

procedure init;
begin
  for i:=(1<<20)-1 downto 0 do
  begin
    fillchar(cnt,sizeof(cnt),0);
    for j:=1 to 20 do
    if i and (1<<(j-1))<>0 then calc(i,j);
    for j:=0 to 20 do
    if cnt[j]=0 then
    begin
      a[i]:=j;
      break;
    end;
  end;
end;

procedure solve;
begin
  readln(n);res:=0;c:=0;
  for i:=1 to n do
  begin
    read(m);
    for j:=1 to m do
    begin
      read(v);
      c:=c or(1<<(v-1));
    end;
    res:=res xor a[c];
  end;
  if res<>0 then writeln(‘YES‘)
  else writeln(‘NO‘);
end;

begin
  init;
  readln(t);
  while t>0 do
  begin
    dec(t);
    solve;
  end;
end.

时间: 2024-08-11 09:26:26

2016多校联合训练1 B题Chess (博弈论 SG函数)的相关文章

2016多校联合训练4 F - Substring 后缀数组

Description ?? is practicing his program skill, and now he is given a string, he has to calculate the total number of its distinct substrings. But ?? thinks that is too easy, he wants to make this problem more interesting. ?? likes a character X very

2014多校联合训练第一场(组队训练)

这是我.potaty.lmz第二次训练,毕竟经验不足,加上水平不够,导致我们各种被碾压. A - Couple doubi: 这道题是道比较水的数论.但我们都没想出来要怎么做.后来是potaty提议打个表看看,然后lmz打出表后发现了规律.我还没细看,待研究后再补全. D - Task: 这道题一看就知道是个贪心(现在只要是有deadline的题我都觉得是贪心了).虽然想出来了,但还是不会严格证明为什么只要取满足task的且y最小(y相等时x最小)的machine就行了. 我的做法是把所有mac

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分相同,第一部分与第二部分对称. 现在给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法,求出以第i个点为中心的回文串长度,记录到数组p中 要满足题目所要求的内容,需要使得两个相邻的回文串,共享中间的一部分,也就是说,左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也是一样. 因为我们已经记录下来以

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&amp;#39;s problem(manacher+二分/枚举)

pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法.求出以第i个点为中心的回文串长度.记录到数组p中 要满足题目所要求的内容.须要使得两个相邻的回文串,共享中间的一部分,也就是说.左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也

hdu 5288||2015多校联合第一场1001题

http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know ∑i

【补题】多校联合训练第二场

第二场 1001 Is Derek lying? Problem Description Derek and Alfia are good friends.Derek is Chinese,and Alfia is Austrian.This summer holiday,they both participate in the summer camp of Borussia Dortmund.During the summer camp,there will be fan tests at i

【补题】多校联合训练第一场

1001  Add More Zero Problem Description There is a youngster known for amateur propositions concerning several mathematical hard problems.Nowadays, he is preparing a thought-provoking problem on a specific type of supercomputer which has ability to s

2015多校联合训练第一场Tricks Device(hdu5294)

题意:给一个无向图,给起点s,终点t,求最少拆掉几条边使得s到不了t,最多拆几条边使得s能到t 思路: 先跑一边最短路,记录最短路中最短的边数,总边数-最短边数就是第二个答案 第一个答案就是在最短路里面求最小割,也就是求最大流,然后根据最短路在建个新图,权为1,跑一边网络流 模板题,以后就用这套模板了 #include <iostream> #include <cstdio> #include <cstring> #include <queue> #incl

多校联合训练第三场

1011 签到题,做过最简单的签到题... 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 #include<vector> 7 #include<set> 8 #include<string> 9 #include<sstream> 10 #i