Alice and Bob CodeForces
来源:互联网 发布:单片机仿真软件程序 编辑:程序博客网 时间:2024/05/16 11:48
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 ofn 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 integersx 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.
The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line containsn distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the set.
Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).
22 3
Alice
25 3
Alice
35 6 7
Bob
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.
#include<bits/stdc++.h>using namespace std;int gcd(int a,int b){ return b?gcd(b,a%b):a;}int save[120];int main(){ int n; while(scanf("%d",&n)!=EOF) { int maxx=0; for(int i=0; i<n; i++) { scanf("%d",&save[i]); if(maxx<save[i]) maxx=save[i]; } int k=maxx; for(int i=0; i<n-1; i++) { for(int j=i+1; j<n; j++) { int c=gcd(save[i],save[j]); k=gcd(k,c); } } if((n-maxx/k)%2==0) printf("Bob\n"); else printf("Alice\n"); }}
- Alice and Bob (CodeForces
- Alice and Bob CodeForces
- 【博弈】Alice and Bob CodeForces
- Alice, Bob and Chocolate CodeForces
- codeforces 6C - Alice, Bob and Chocolate
- CodeForces 347 C. Alice and Bob
- Codeforces 6C. Alice, Bob and Chocolate
- CodeForces 6C - Alice, Bob and Chocolate
- Codeforces 347C Alice and Bob
- [CodeForces 346A]Alice and Bob[数学]
- codeforces-346A-Alice and Bob【数论】
- CodeForces 6C Alice, Bob and Chocolate
- CodeForces 346A Alice and Bob
- CodeForces 346A Alice and Bob
- CodeForces 347 C. Alice and Bob
- codeforces#347div2 C. Alice and Bob
- Codeforces 347C - Alice and Bob
- CodeForces 347C Alice and Bob
- JS之参数作用域
- Git报错误:Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
- PHPStorm IDE 快捷键(MAC)
- Gson解析和Volley框架并用
- Java垃圾回收机制面试回答
- Alice and Bob CodeForces
- Maven + myeclise集成,及web项目创建,和导入现成的web项目
- 如何配置 UAA 作为 SP 和 IdP
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测 (时间分治+带撤销并查集)
- c3p0加载properties配置文件 报错 Access denied for user 'Administrator'@'localhost' (using password: YES)
- DBoW2视觉词袋原理
- Java中的事务——JDBC事务和JTA事务
- 排序与查找实例(四):归并排序
- 【POST 与 GET的真正区别】深入浅出