HDU - 3980 Paint Chain

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

 

组合游戏的和: 假设有K个组合游戏,每次任选一个子游戏进行操作,其他的游戏局面不变,不能操作的游戏者输。

SG函数和SG定理:

\large SG(X)=mex(S)

\large S\large X 的后继状态 \large SG 值的集合, \large mex(S)  就是不在  \large S  内的最小非负整数。

\large SG(x)=0  当且仅当  \large x  是必败状态(因为\large x后继状态是空集,所以为0)

#include <bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for(int i=a;i<b;++i)

int n,m;
const int N=1010;
int SG[N];


int dfs(int x,int m){
	//if(x==m)return 1;
    if(SG[x]!=-1)return SG[x];

    //必败态,没有后继状态,所以SG[x]=0;
    if(x<m)return 0;

    //后继状态SG值
    int mex[N];
    memset(mex,0,sizeof(mex));
    int res=0;
    for(int i=1;i+m-1<=x;i++){
        int t1=dfs(i-1,m),t2=dfs(x-(i+m-1),m);
       // printf("x:%d t1:%d t2:%d t1^t2:%d\n",x,t1,t2,t1^t2);
        mex[t1^t2]=1;
    }
    for(int i=0;;i++){
		if(!mex[i]){
			SG[x]=i;break;
		}
    }
   // printf("x:%d SG:%d\n",x,SG[x]);
    return SG[x];
}

int main()
{
    int T;
    scanf("%d",&T);
    rep(kase,1,T+1){
        scanf("%d %d",&n,&m);
        
        memset(SG,-1,sizeof(SG));
       // SG[0]=0;

        printf("Case #%d: ",kase);
        if(m>n){
            printf("abcdxyzk\n");
        }else{
            int ans=dfs(n-m,m);
			//printf("**ans:%d\n",ans);
            if(ans==0)printf("aekdycoin\n");
            else printf("abcdxyzk\n");
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值