【CodeForces - 347C 】Alice and Bob (思维,数学,等差数列)

版权声明:欢迎学习我的博客,希望ACM的发展越来越好~ https://blog.csdn.net/qq_41289920/article/details/84846720

题干:

It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).

If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.

Input

The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the set.

Output

Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).

Examples

Input

2
2 3

Output

Alice

Input

扫描二维码关注公众号,回复: 4423522 查看本文章
2
5 3

Output

Alice

Input

3
5 6 7

Output

Bob

Note

Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

题目大意:

  给你一个数的序列,定义一种操作:任选两个不同的数,将他们的差的绝对值加入序列中(注意操作中不涉及删除元素)。问你需要多少次操作可以操作到无法操作,如果操作次数是奇数 那就Alice赢,偶数就Bob赢,让你输出最后谁获得胜利。

解题报告:

  其实原题干不是这么写的,,原题看起来像是个博弈问题,,但是其实分析以后不难发现,其实就是个操作次数的奇偶问题。(其实也可能是可以证明,给定一个初始序列之后,那么操作次数就已经固定了,我们只需要求出这个数是奇数还是偶数就可以了。)

  分析到这一步,然后我们从结果入手,结果序列一定是不能再操作的,我们假设这个序列是个递增序列的话(其实他加这个绝对值的原因就是告诉你:你可以把这个序列当成一个递增序列去看,,因为他添加数了啊也没说添加到哪里,如果默认添加到最后,那么这个序列肯定就不是一个递增序列了,所以他说有绝对值,就是为了让你把它当成一个排好序的递增的),那么我们任意两项的差都在这个序列中,也就是说这个数列一定是一个等差数列,并且排好序后的最大项一定是an,那么我们能得到的最小值是多少呢?根据求gcd的原理我们知道,两个数相减,得到的一定是两个数的gcd的倍数。根据这个原理,我们知道最小的数一定是这n个数的gcd,求值,也就是最终序列的a[1]。现在我们有了最终序列的a[1]和a[all],现在要求一共操作了多少次才变成这个序列。因为每一次操作只增加一个元素,那么增加了多少个元素,肯定就操作了多少次呗。那么增加了多少个元素呢?最终序列元素个数为all,初始序列为n个,那作差就是答案啊。然后判断这个答案的奇偶性就可以了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
int a[MAX];
int main()
{
	int n;
	cin>>n;
	for(int i = 1; i<=n; i++) scanf("%d",a+i);
	sort(a+1,a+n+1);
	int g = a[1];
	for(int i = 2; i<=n; i++) g = __gcd(a[i],g);
	int tmp = a[n]/g - n;
	if(tmp&1) puts("Alice");
	else puts("Bob");
	return 0 ;
 }

猜你喜欢

转载自blog.csdn.net/qq_41289920/article/details/84846720