您的位置:首页 > 其它

Sicily 1924. Turn Over the Coins

2015-05-09 11:24 369 查看
题目



思路

这题的题目说得不是很清楚,其实这是一个很经典的翻硬币游戏。

有N个硬币,我们每次先选一个正面朝上的硬币,将其翻转,然后从这个硬币的左边选择0~2个无论正反的硬币翻转。

最后没得翻的人为负者(也即硬币都是反面)。

思路来源于这篇博客:

http://blog.sina.com.cn/s/blog_8f06da99010125ol.html

代码

[code]#include <stdio.h>

short sg[1005];

void init() {
    for (int i = 0; i < 1001; i++) {
        int temp = i << 1;
        int count = 0;
        while (temp) {
            if (temp & 1) count++;
            temp >>= 1;
        }
        sg[i] = (i << 1) + (count & 1);
    }
}

int main() {

    init();

    int CaseNum;
    scanf("%d\n", &CaseNum);

    while (CaseNum--) {
        int Ans = 0, k = 0;
        char text[2005];
        gets(text);
        gets(text);
        for (int i = 0; text[i] != '\0'; i++) {
            if (text[i] == 'H') Ans ^= sg[k++];
            if (text[i] == 'T') k++;
        }
        printf(Ans ? "Alice\n" : "Bob\n");
    }

    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: