Gym - 100814L Candy Jars (博弈)


L. Candy Jars
time limit per test
1.0 s
memory limit per test
1024 MB
input
standard input
output
standard output

Alice and Bob love to play the following game, they have N jars and the rules are as follows:

  • Each jar has a strictly positive number of candies.
  • Alice plays first and the two players alternate.
  • In his/her turn, the player selects any jar X, throws away all candies in all the other jars and redistributes the candies in X among all jars in anyway he/she wishes, as long as in the end there is at least one candy in each jar (including X).
  • The player who cannot make a move in his/her turn loses the game.

Assuming both players play optimally, you are asked the following question who wins the game? Playing optimally means that both players will have insight into all possible next moves and will play in such a way to maximize their chance of winning without making a mistake. However, if all moves lead to the other player winning, then this player still has to play, and any move would be equivalent.

Input

The first line contains the number of test cases T. Each of the next T lines contains an integer (2 ≤ N ≤ 1, 000) the number of jars, andN integers (1 ≤ ai ≤ 1000) where ai is the number of candies in jar i.

Output

Output T lines, one for each test case, containing "Alice" if Alice wins the game, or "Bob" otherwise.

Examples
input
3
4 1 2 3 3
4 1 2 3 4
2 1 3
output
Bob
Alice
Bob

123

博弈,  选择一个罐子,扔掉其他, 将选择的罐子里的数目 分配给所有的罐子,(每个罐子至少要分到一个) 如果有罐子分不到, 则 输;

可以发现 如果所有的罐子里的数目 都

并且 当所有罐子 中 存在几个 罐子里的数目为 为  n - n-1  那么 无论是选择n  还是选择 n-1  先手一定赢;

否则先手一定输;

所以: 先手赢得条件为 存在 罐子里的数目 x % (n*(n-1)) =n || =0 即 先手输  为  1<=x % (n*(n-1))


#include 
#include 
using namespace std;

int main()
{
	int sum=0;
	int T;
	cin>>T;
	int n;
	while(T--)
	{
		sum=0;
		scanf("%d",&n);
		int x;
		int flag=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&x);
			
			if(flag) continue;
			 
			int t= x%((n-1)*n);
			 
			if(t=1) 
			 	continue;
			flag=1;
		}
		if(!flag)
			printf("Bob\n");
		else
			printf("Alice\n");
	}
}


转载于:https://www.cnblogs.com/sizaif/p/9078507.html

你可能感兴趣的:(Gym - 100814L Candy Jars (博弈))