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 boxhaving 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 leastone 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 verysmart and always follows a perfect strategy.

InputThere will be at most 300 test cases. Each test case contains an integer n (2 ≤ n ≤ 109) in a singleline. The input terminates by n = 0.

Output

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

Sample Input

4

 0

Sample Output

Alice 

Bob

Alice

题意:有两个相同的盒子,其中一个盒子有n个球,另一个有1个球,每次把较小的那个数拿走,然后把较大的数分成两部分,使得操作后每个盒子至少有1个球,如果无法操作,
则当前游戏者输,判断先手(Alice)还是后手(Bob)胜

每次将较大的数分成两部分时 , 较小的数删去 , 取较大的数再分 , 那么所取的数为(n+1)/2 ~ n-1;

由此:

const int maxn = 150;
int F[maxn] , sg[maxn] , hush[maxn];
void getsg(int n)
{
	memset(sg , 0 ,sizeof(sg));
	sg[1] = 0;
	sg[2] = 1;
	for(int i = 3 ; i <= n ; i++)
	{
		memset(hush , 0 , sizeof(hush));
		for(int j = (i+1)/2 ; j < i; j++)
		{
			hush[sg[j]] = 1;
		}
		for(int j = 0 ; j <= n ; j++)
		{
			
			if(hush[j] == 0)
			{
				sg[i] = j;
				break;
			}
		}
	}
	for(int i = 0 ; i < n ; i++)
	{
		cout << i <<":" << sg[i]<<endl;
	}
}

通过SG函数可以看出每到2^n - 1 时后手赢。

AC代码:

#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
const int maxn = 1e9;
int f[10000];
int main()
{
	int n;
	while(~scanf("%d" , &n)&&n)
	{
		int ans = 0 , flag = 0;
		for(int i = 0 ; i  < 10000 ; i++)
		{
			f[ans++] = pow(2 , i) -1;
		}
		for(int i  = 0 ; i < ans ; i++)
		{
			if(n == f[i])
			{
				flag = 1;
				break;
			}
		}
		if(flag == 1)
		{
			printf("Bob\n");
		}
		else
		{
			printf("Alice\n");
		}
	}
	return 0;
 }