Nbut 1107--Box Game —————— "Game class"

Source: Internet
Author: User

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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.