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 - n-1  那么 无论是选择n  还是选择 n-1  先手一定赢;

否则先手一定输;

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


#include <stdio.h>
#include <iostream>
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<n&&t>=1) 
			 	continue;
			flag=1;
		}
		if(!flag)
			printf("Bob\n");
		else
			printf("Alice\n");
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值