zoukankan      html  css  js  c++  java
  • hdu 5724 SG+状态压缩

    Chess

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1821    Accepted Submission(s): 799

    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
    /*
    hdu 5724 SG+状态压缩
    
    感觉上是博弈,而且很久以前就看了看SG,但是并没怎么系统地去学习zzz。
    首先可以把棋盘n行看成n个石碓,用1表示有棋子,0表示没有的话,能够用二进制表示出所有的状态:
    1000100这个可以转换成 0100100 1000010等等
    
    然后就能利用公式求出每种情况的SG(枚举 1~(1<<20))
    得出每一行的状态计算即可
    
    hhh-2016-08-01 17:28:17
    学习:
    //http://blog.csdn.net/luomingjun12315/article/details/45555495
    */
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <functional>
    #include <vector>
    #include <queue>
    using namespace std;
    #define lson  (i<<1)
    #define rson  ((i<<1)|1)
    typedef long long ll;
    using namespace std;
    const ll mod = 1e9 + 7;
    const ll INF = 0x3f3f3f3f;
    const int maxn = 1000100;
    
    int vis[22];
    int sg[1<<20];
    
    int SG(int cur)
    {
        memset(vis,0,sizeof(vis));
        for(int i = 20; i >= 0; i--)
        {
            if(cur & (1<<i))
            {
                for(int j = i-1; j >= 0; j--)
                {
                    if(!(cur & (1 << j)))
                    {
                        int tmp = cur;
                        tmp ^= ((1<<i)^(1<<j));
                        vis[sg[tmp]] = true;
                        break;
                    }
                }
            }
        }
        for(int i = 0 ; i <= 20; i++)
        {
            if(!vis[i])
                return i;
        }
        return 0;
    }
    
    int main()
    {
        memset(sg,0,sizeof(sg));
        for(int i = 1; i < (1 << 20); i++)
            sg[i] = SG(i);
        int T,n,x;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            int ans = 0;
            for(int i = 1;i <= n;i++)
            {
                int m,cur = 0;
                scanf("%d",&m);
                for(int j = 1;j <= m;j++)
                {
                    scanf("%d",&x);
                    cur |= 1 << (20-x);
                }
                ans ^= sg[cur];
            }
            if(ans )
                printf("YES
    ");
            else
                printf("NO
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    mongo批量删除js示例
    Mongo压测介绍
    线性代数学习笔记(1)--二维向量点积本质(仅供自己理解)
    墨菲定律的正确解读
    spring cloud 2020.0.1踩坑记录-bootstrap不生效等
    记一次网络质量原因导致接口调用超时的调查过程
    .NET Debugging Demos Lab 2: Crash
    .NET Debugging Demos Lab 3: Memory
    Hang caused by GC
    .NET Debugging Demos Lab 4: High CPU hang
  • 原文地址:https://www.cnblogs.com/Przz/p/5757353.html
Copyright © 2011-2022 走看看