zoukankan      html  css  js  c++  java
  • hdu_5724_Chess(组合博弈)

    题目链接:hdu_5724_Chess

    题意:

    给你一个n行20列的棋盘,棋盘里面有些棋子,每个棋子每次只能往右走一步,如果右边有棋子,可以跳过去,前提是最右边有格子,如果当前选手走到没有棋子可以走了,那么就算输,问你先手是否会赢

    题解:

    一看就知道是组合博弈的问题,关键在于如果求SG值,这里要把一行看成一个状态,然后根据SG值的定义去求,如果不知道SG的求法,那去找度娘吧。预处理出一行所有状态的SG,然后对每一行异或一下就行了。

     1 #include<cstdio>
     2 #include<cstring>
     3 #define F(i,a,b) for(int i=a;i<=b;i++)
     4 int sg[1<<20];
     5 
     6 void init(){
     7     int end=(1<<20)-1;
     8     F(i,0,end){
     9         int last=-1,h[25],now=0;
    10         memset(h,-1,sizeof(h));
    11         F(j,0,19){//枚举下一步能达到的状态
    12             if(i<(1<<j))break;
    13             if(!((i>>j)&1))last=j;
    14             if(((i>>j)&1)&&~last)h[sg[i^(1<<j)^(1<<last)]]=1;
    15         }
    16         while(~h[now])now++;
    17         sg[i]=now;
    18     }
    19 }
    20 
    21 int main(){
    22     init();
    23     int t;
    24     scanf("%d",&t);
    25     while(t--){
    26         int n,ans=0,tp,ttp;
    27         scanf("%d",&n);
    28         F(i,1,n){
    29             scanf("%d",&tp);
    30             int now=0;
    31             F(j,1,tp)scanf("%d",&ttp),now^=1<<(20-ttp);
    32             ans^=sg[now];
    33         }
    34         if(ans)puts("YES");else puts("NO");
    35     }
    36     return 0;
    37 }
    View Code



  • 相关阅读:
    函数式宏定义与普通函数
    linux之sort用法
    HDU 4390 Number Sequence 容斥原理
    HDU 4407 Sum 容斥原理
    HDU 4059 The Boss on Mars 容斥原理
    UVA12653 Buses
    UVA 12651 Triangles
    UVA 10892
    HDU 4292 Food
    HDU 4288 Coder
  • 原文地址:https://www.cnblogs.com/bin-gege/p/5696068.html
Copyright © 2011-2022 走看看