【POJ 2484】A Funny Game

Meaning of the questions:

Alice and Bob are playing a silly game, n pawn in a circle, the two take turns removed from one or two pieces, but when taking two pieces must be continuous.

After leaving the gap piece is removed, the pieces separated by a gap discontinuity. Alice first take, take away the last man to win a pawn. If you are taking the optimal strategy, who would win?

Solution

Can be found when the \ (n-\) or less \ (2 \) when \ (Alice \) win. When \ (n-\) is equal to \ (3 \) or \ (4 \) when \ (Bob \) win.

After the case may think:

  • \ (n-\) is an odd number: the upper hand selected \ (1 \) particles, selected from across the upper hand flip \ (2 \) particles. Is selected from the upper hand \ (2 \) pieces empathy.
  • \ (n-\) is an even number: the upper hand selected \ (1 \) particles, selected from across the flip \ (1 \) particles. \ (2 \) pieces empathy.

So what can guarantee it? After two such operations, the entire ring will be divided into two sections, the length of which two are equal, and the upper hand is at this time \ (Alice \) . Such \ (Alice \) what to take, \ (Bob \) will take the same number of opposite, thus ensuring \ (Bob \) will win.

Code

#include<cstdio>

int n;

int read() {
    int x = 0, f = 1; char s;
    while((s = getchar()) > '9' || s < '0') if(s == '-') f = -1;
    while(s >= '0' && s <= '9') {
        x = (x << 1) + (x << 3) + (s ^ 48);
        s = getchar();
    }
    return x * f;
    
}

int main() {
    while(n = read(), n) puts(n <= 2 ? "Alice" : "Bob");
    return 0;
}

Guess you like

Origin www.cnblogs.com/AWhiteWall/p/12320677.html