zoukankan      html  css  js  c++  java
  • HDU 5742 Chess SG函数博弈

    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(T100), indicates the number of test cases.

    For each test case, the first line contains a single integer n(n1000), the number of lines of chessboard.

    Then n lines, the first integer of ith line is m(m20), indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1pj20)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+10, M = 2e5+20, mod = 1e9+7, inf = 2e9;
    
    int sg[1<<22],vis[30];
    void init() {
        int NN = 1<<20;
        for(int i = NN; i >= 0; --i) {
            memset(vis,0,sizeof(vis));
            int last = -1;
            for(int j = 19; j >= 0; --j) {
                if((i&(1<<j)) == 0) last = j;
                else  {
                    if(last == -1) continue;
                    int now = i - (1<<j) + (1<<last);
                    vis[sg[now]] = 1;
                }
            }
            for(int j = 0; j <= 25; ++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 = 0;
                for(int i = 1; i <= m; ++i) {
                    int now = 0;
                    scanf("%d",&x);
                    while(x--) {
                        scanf("%d",&y);
                        y--;
                        now += (1<<(y));
                    }
                    ans ^= sg[now];
                }
                if(ans) puts("YES");
                else puts("NO");
            }
            return 0;
    }
  • 相关阅读:
    临时禁用大型列表上的列表视图阈值
    临时禁用大型列表上的列表视图阈值
    SharePoint Foundation 2010 托管客户端对象模型概述 创建 Windows 控制台托管的客户端对象模型应用程序
    如何隐藏MOSS2010的网站操作菜单
    MOSS2010的列表视图参数设置以及列表记录样式设置
    使用SharePoint Server 2010搜索PDF文档
    Sharepoint2010如何使用Linq to Sharepoint
    水晶報表字段超鏈結4/28
    4月21自考4/23
    [轉]統籌方法華羅庚
  • 原文地址:https://www.cnblogs.com/zxhl/p/6011855.html
Copyright © 2011-2022 走看看