hdu3980SG函数

Paint Chain

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


 

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

2011 Multi-University Training Contest 14 - Host by FZU

 

Recommend

We have carefully selected several similar problems for you:  3972 3973 3974 3975 3976 

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int sg[1005];
int t;
int SG(int n,int m)
{
    if(n<m)
        return sg[n]=0;
    if(sg[n]!=-1)
        return sg[n];
    bool vis[1005];
    memset(vis,false,sizeof(vis));
    for(int i=0;i<=n-m;i++)
        vis[SG(i,m)^SG(n-m-i,m)]=true;
    for(int i=0;i<=1000;i++)
        if(vis[i]==false)
    {
        sg[n]=i;
        break;
    }
    return sg[n];
}
int main()
{
    scanf("%d",&t);
    int w=0;
    int n,m;
    while(t--)
    {w++;
    scanf("%d%d",&n,&m);
        memset(sg,-1,sizeof(sg));
        if(n<m||SG(n-m,m))
            printf("Case #%d: abcdxyzk\n",w);
            else
                printf("Case #%d: aekdycoin\n",w);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sdauguanweihong/article/details/89508832