UVA 12293 Box Game (game starter)

Source: Internet
Author: User

Title Link: Box Game


Surface:

12293 Box GameThere is identical boxes. One of them contains n balls, while the other box contains one ball.
Alice and Bob invented a game with the boxes and balls, which is played as follows:
Alice and Bob moves Alternatively, Alice moves first. For each move, the player finds out the box
Have fewer number of balls inside, and empties that box (the balls inside would be removed forever),
And redistribute the balls in the other box. After the redistribution, each box should contain at least
One ball. If A player cannot perform a valid move, he loses. A Typical game is shown below:
When the both boxes contain only one ball, Bob cannot does anything more, so Alice wins.
Question:if Alice and Bob is both clever enough, who'll win? Suppose both of them is very
Smart and always follows a perfect strategy.


Input
There'll is at the most test cases. Each test case contains an integer n (2≤n≤109) in a single
Line. The input terminates by n = 0.


Output
For each test case, print a, the name of the winner.


Sample Input
2
3
4
0


Sample Output
Alice
Bob
Alice


Solving:

Game basically do not, this problem is very good push, first simulation found 1,3,7 as must lose state, as long as the latter situation can let decomposition into the previous must lose the state to Bob so all is Alice win, it is easy to launch the next must lose 15. Because at this time the smallest can only get 8. This problem can also find the law, 1,3,7,15,31 ... always 2^n-1.


Code:

#include <iostream>using namespace Std;int main () {int N;while (cin>>n&&n) {  bool flag=true;  while (n)  {  if ((n-1)%2)  {  flag=false;  break;  }  n= (n-1)/2;  }  if (flag) cout<< "bob\n";  else cout<< "alice\n";}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVA 12293 Box Game (game starter)

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.