uva 12293 - Box Game(组合游戏)

题目链接:uva 12293 - Box Game

题目大意:有两个盒子,第一个盒子装有n个球,第二个盒子装又1个球,每次操作将少的盒子中的球全部拿掉,并从另一个盒子中取一些球放入该盒子,不能使另一个盒子中球的个数为0。两人轮流操作,问说最后谁胜。

解题思路:n如果为2i1那么先手必败。

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

bool judge (int n) {
    for (int i = 1; i < 32; i++)
        if (n == (1<<i) - 1)
            return false;
    return true;
}

int main () {
    int n;
    while (scanf("%d", &n) == 1 && n) {
        printf("%s\n", judge(n) ? "Alice" : "Bob");
    }
    return 0;
}

你可能感兴趣的:(uva 12293 - Box Game(组合游戏))