# UVA 12293 Box Game（博弈入门）

## 12293 Box Game

There are two 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
having fewer number of balls inside, and empties that box (the balls inside will 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 both boxes contain only one ball, Bob cannot do anything more, so Alice wins.
Question: if Alice and Bob are both clever enough, who will win? Suppose both of them are very
smart and always follows a perfect strategy.

Input
There will be at most 300 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 single line, the name of the winner.

Sample Input
2
3
4
0

Sample Output
Alice
Bob
Alice

博弈基本不会，这道题很好推，先模拟一下发现1,3,7为必输态，只要后面的情况能够让分解为之前的必输态给Bob那么都是Alice赢，很容易推出下一必输态为15。因为此时最小只能得到8了。这道题也可以找规律，1,3,7,15,31...总是2^n-1。

#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";
}
}

• 本文已收录于以下专栏：

## UVA 12293 Box Game 组合游戏/SG定理+找规律

#include #include #include #include using namespace std; int sg[202];//sg[i]表示连续的x个空格子组成的棋盘的SG值 ...
• a601025382s
• 2013年08月06日 10:52
• 966

## UVa 12293 Box Game（博弈，SG函数）

• Baoli1008
• 2015年03月10日 10:46
• 328

## uva 12293 - Box Game(组合游戏)

• u011328934
• 2014年08月06日 23:03
• 852

## UVA - 12293 Box Game (规律)

Description   Box Game  There are two identical boxes. One of them contains ...
• u011345136
• 2014年08月28日 09:31
• 947

## UVa12293 - Box Game(博弈)

There are two identical boxes. One of them contains n balls, while the other box contains one ball. ...
• wuli2496
• 2014年08月28日 16:34
• 498

## UVA 12293 Box Game

Description   Box Game  There are two identical boxes. One of them contains ...
• ultimater
• 2012年10月20日 20:52
• 1307

## UVA 1482 - Playing With Stones(SG打表规律)

UVA 1482 - Playing With Stones 题目链接 题意：给定n堆石头，每次选一堆取至少一个，不超过一半的石子，最后不能取的输，问是否先手必胜 思路：数值很大，无...
• u011217342
• 2014年07月16日 12:15
• 1529

## UVA 12293 - Box Game(博弈)

UVA 12293 - Box Game 题目链接 题意：两个盒子，一开始一个盒子有n个球，一个只有1个球，每次把球少的盒子中球消掉，把多的拿一些球给这个盒子，最后不能操作的输（球不能少于...
• u011217342
• 2014年07月16日 15:28
• 987

## UVA 12293 Box Game（博弈入门）

• David_Jett
• 2015年07月09日 22:58
• 704

## UVA 4855 Hyper Box

You live in the universe X where all the physical laws and constants are different from ours. For ex...
• ling_du
• 2015年08月20日 17:45
• 547

举报原因： 您举报文章：UVA 12293 Box Game（博弈入门） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)