Box GamesTime
limit:1000MS
Memory Limit:65535KB
64bit IO Format: SubmitStatusPracticenbut 1107
Description
There are two identical boxes, one with n balls and the other with a ball. Alice and Bob invented a game with the following rules: Alice and Bob take turns, and when Alice first operates each operation, the player first looks at the number of balls in which box is less, then empties the box (the ball in the box is thrown away), and then takes the ball from the other box to the box. , making two boxes have at least one ball. If a player is unable to operate, he or she loses. is a typical game:
In the face of two boxes with one ball, Bob couldn't continue, so Alice won. Your task is to find out who will win. Suppose both are smart and always take the best strategy.
Input
Enter up to 300 sets of test data. Only one row per group of data, containing an integer n (2<=n<=10^9). The input end flag is n=0.
Output
For each set of data, output the name of the winner.
Sample Input
2 3 4 0
Sample Output
Alice Bob Alice
Hint
No
Problem-solving ideas: Through the 2^m-1 from the main to the big data projections, can be launched, when N is the time, the initiator loses.
#include <stdio.h>using namespace Std;bool judge (int x) { int cnt=0; while (x) { if (x&1) cnt++; x>>=1; } if (cnt==1) return false; else return true;} int main () { int n; while (scanf ("%d", &n)!=eof&&n) { if (judge (n+1)) { printf ("alice\n"); } else{ printf ("bob\n"); } } return 0;}
Nbut 1107--Box Game —————— "Game class"