zoukankan      html  css  js  c++  java
  • HDU 3980 Paint Chain (sg函数)

    Paint Chain

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 804    Accepted Submission(s): 292


    Problem Description
    Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one player must paint a unpainted beads. Whoever is unable to paint in his turn lose the game. Aekdycoin will take the first move.

    Now, they thought this game is too simple, and they want to change some rules. In each turn one player must select a certain number of consecutive unpainted beads to paint. The other rules is The same as the original. Who will win under the rules ?You may assume that both of them are so clever.
     
    Input
    First line contains T, the number of test cases. Following T line contain 2 integer N, M, indicate the chain has N beads, and each turn one player must paint M consecutive beads. (1 <= N, M <= 1000)
     
    Output
    For each case, print "Case #idx: " first where idx is the case number start from 1, and the name of the winner.
     
    Sample Input
    2 3 1 4 2
     
    Sample Output
    Case #1: aekdycoin Case #2: abcdxyzk
     
    Author
    jayi
     
    Source

    题意:一圈 N 个的硬币, 两个玩家轮流取,每次他们可以取M个连续硬币, 最后一个不能取的为负;

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    
    using namespace std;
    
    const int N=1010;
    
    int n,m,sg[N];
    
    int mex(int x){
        if(sg[x]!=-1)
            return sg[x];
        int re[N];
        memset(re,0,sizeof(re));
        for(int i=0;i<=x-m-i;i++)
            re[mex(i)^mex(x-m-i)]=1;
        int i=0;
        while(re[i]!=0)
            i++;
        return sg[x]=i;
    }
    
    int main(){
    
        //freopen("input.txt","r",stdin);
    
        int t,cases=0;
        scanf("%d",&t);
        while(t--){
            memset(sg,-1,sizeof(sg));
            printf("Case #%d: ",++cases);
            scanf("%d%d",&n,&m);
            if(n<m){
                puts("abcdxyzk");
                continue;
            }
            if(m==1){
                if(n&1)
                    puts("aekdycoin");
                else
                    puts("abcdxyzk");
                continue;
            }
            if(!mex(n-m))
                puts("aekdycoin");
            else
                puts("abcdxyzk");
        }
        return 0;
    }
  • 相关阅读:
    使用Identity Server 4建立Authorization Server (3) yangxu
    Asp.Net Core 之 基于 Open Connect ID 身份验证
    Pandas数据结构 2
    Pandas 数据结构 DataFrame
    大数据加工平台数据清洗
    Python电影数据分析
    Pandas安装
    Pandas 读取CSV
    Mongo Python 增、删、改、查等操作
    读书笔记人月神话其三
  • 原文地址:https://www.cnblogs.com/jackge/p/3232616.html
Copyright © 2011-2022 走看看