zoukankan      html  css  js  c++  java
  • hdu 5724 Chess(博弈)

    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
     
    Author
    HIT
     
     
    将棋盘的状态压缩,然后预处理出所有状态的sg值,然后就是普通的组合游戏做法了。
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    int sg[(1<<20) + 1010];
    int vis[1010];
    void init(int x) {
        sg[1] = 0;
        memset(vis, 0, sizeof(vis));
        for(int i = 20; i >= 0; i--) {
            if((1 << i) & x) {
                for(int j = i - 1; j >= 0; j--) {
                    if(!((1 << j) & x)) {
                        vis[sg[x ^ (1 << j) ^ (1 << i)]] = 1;
                        break;
                    }
                }
            }
            for(int j = 0; ; j++) if(!vis[j]) {
                sg[x] = j;
                break;
            }
        }
    }
    int main() {
        int t;
        for(int i = 0; i < (1 << 20); i++) init(i);
        scanf("%d", &t);
        while(t--) {
            int n, m;
            scanf("%d", &n);
            int ans = 0;
            for(int i = 1; i <= n; i++) {
                scanf("%d", &m);
                int tmp = 0;
                for(int j = 1; j <= m; j++) {
                    int x;
                    scanf("%d", &x);
                    tmp ^= 1 << (20 - x);
                }
                ans ^= sg[tmp];
            }
            if(ans) puts("YES");
            else puts("NO");
        }
    }
  • 相关阅读:
    div在父集高度未知的情况下垂直居中的方法
    固比固布局 圣杯布局 css实现传统手机app布局
    img标签的onerror事件
    vue中的swiper element ui
    前后端分离跨域 关于前后端分离开发环境下的跨域访问问题(angular proxy=>nginx )
    自己开发的网页在跳转至微信公众号文章后,点击微信的返回,无法返回原网页
    关于audio元素在实际项目中遇到的问题总结
    移动端HTML5<video>视频播放优化实践
    数据类型转换
    穿越宇宙的邀请函——镜像图片技巧
  • 原文地址:https://www.cnblogs.com/lonewanderer/p/5690581.html
Copyright © 2011-2022 走看看