日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 347C 】Alice and Bob (思维,数学,等差数列) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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

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

?

總結

以上是生活随笔為你收集整理的【CodeForces - 347C 】Alice and Bob (思维,数学,等差数列)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。