zoukankan      html  css  js  c++  java
  • HDU1851_A Simple Game_求sg

    /*
    *State: 1851    0MS    268K    862 B    C++
    *题目大意:
    *        (类似)给定n堆石子,然后规定每堆石子只能
    *        取的个数,然后最先取完者胜,要求判断局势的奇异。
    *解题思路:
    *        分别求sg即可。
    */
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    
    const int MAX = 21;
    int get_sg(int n, int t)
    {
        int sg[MAX], vst[MAX];
        for(int i = 0; i < MAX; i++)
        {
            int h = 1;
            memset(vst, 0, sizeof(vst));
            while(i >= h && h <= t)
                vst[sg[i - h++]] = 1;
            for(int j = 0; j <= i; j++)
            {
                if(!vst[j])
                {
                    sg[i] = j;
                    break;
                }
            }
        }
        return sg[n];
    }
    
    int main(void)
    {
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif
        int cas;
        scanf("%d", &cas);
        while(cas--)
        {
            int n, yihuo = 0;
            scanf("%d", &n);
            for(int i = 0; i < n; i++)
            {
                int pile, pile_tmp, lit;
                scanf("%d %d", &pile, &lit);
                pile_tmp = get_sg(pile, lit);
                yihuo ^= pile_tmp;
            }
            if(!yihuo)
                printf("Yes\n");
            else
                printf("No\n");
        }
        return 0;
    }
  • 相关阅读:
    codeforces-1139 (div2)
    codeforces-1140 (div2)
    codeforces-1141 (div3)
    第四届CCCC团体程序设计天梯赛 后记
    BZOJ 3674 可持久化并查集
    你能回答这些问题吗
    [JSOI2008]最大数
    关路灯
    愤怒的小鸟
    推销员
  • 原文地址:https://www.cnblogs.com/cchun/p/2611042.html
Copyright © 2011-2022 走看看