zoukankan      html  css  js  c++  java
  • ZOJ 2083 Win the Game

    //ZOJ的类似题
    //State: ZOJ2083    C++    0    188
    //题目大意:A和B轮流给n条线染色(A先),每人每次只能染一条
    //          线的一段(长度为2)。不能染色者为输。
    
    #include <iostream>
    #include <stdio.h>
    #include <cstring>
    using namespace std;
    
    const int MAX = 55;
    int sg[MAX];
    int get_sg(int n)
    {
        if(sg[n] != -1)
            return sg[n];
        if(!n || n == 1)
            return sg[n] = 0;
        bool vst[MAX] = {false};
        if(n >= 2)
        {
            int t = n - 2, t2 = t / 2;
            for(int i = 0; i <= t2; i++)
            {
                int s = get_sg(t - i) ^ get_sg(i);
                vst[s] = true;
            }
        }
        for(int i = 0; i < MAX; i++)
        {
            if(!vst[i])
                return sg[n] = i;
        }
    }
    
    int main(void)
    {
        int n;
        memset(sg, -1, sizeof(sg));
        while(scanf("%d", &n) == 1)
        {
            int m, yihuo = 0;
            for(int i = 0; i < n; i++)
            {
                scanf("%d", &m);
                yihuo ^= get_sg(m);
            }
            if(!yihuo)
                printf("No\n");
            else
                printf("Yes\n");
        }
        return 0;
    }
  • 相关阅读:
    css中!important的用法
    mysql分区
    js 随机生成信用卡号
    js argument
    lnmp
    php的mcrypt
    php gd
    php socket
    最优服务次序问题 水 NOJ1254
    众数问题 NOJ 1207
  • 原文地址:https://www.cnblogs.com/cchun/p/2623084.html
Copyright © 2011-2022 走看看