[博弈论]Paint Chain

Paint Chain

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

 

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

#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <memory.h>

using namespace std;

int result[1001];
bool g[1001];

void compute(int count, int paints) {
    int i;

    int subCount = count - paints;

    if (subCount < 0) {
        result[count] = 0;
        return;
    }

    memset(g, false, sizeof(g));

    for (i = 0; i <= subCount && i <= subCount - i; ++i) {
        g[result[i] ^ result[subCount - i]] = true;
    }

    for (i = 0; ;++i) {
        if (g[i] == false) {
            result[count] = i;
            break;
        }
    }
}

int main()
{
    int i, j;

    int num;
    int beads;
    int paints;

    scanf("%d", &num);
    for (i = 0; i < num; ++i) {
        memset(result, -1, sizeof(result));
        scanf("%d %d", &beads, &paints);

        if (paints > beads) {
            printf("Case #%d: abcdxyzk\n", i + 1);
            continue;
        }

        beads -= paints;

        for (j = 0; j <= beads; ++j) {
            compute(j, paints);
        }

        if (result[beads] == 0) {
            printf("Case #%d: aekdycoin\n", i + 1);
        } else {
            printf("Case #%d: abcdxyzk\n", i + 1);
        }
    }

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值