数学--数论--Alice and Bob (CodeForces - 346A )推导
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.
游戏结束的标志是无法取出两个数字,他们的差值不在序列中。也就是说,最终状态是一个首项等于公差的等差序列。
求出这个等差数列的项数-n,就是游戏进行的回合。所以我们要先求出首项。设首项为d,接下来就是d+d,d+2d….
后面几项都是首项的倍数,所以我们可以用gcd(a1,a2,a3…an)求出。ans = an / gcd(a1,a2…an) - n;
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
return b==0? a:gcd(b,a%b);
}
int a[101];
int main()
{
int n;
int maxn = 0;
scanf("%d", &n);
for(int i=0;i<n;i++)
{
scanf("%d", &a[i]);
maxn = max(maxn, a[i]);
}
int tmp = maxn;
for(int i=0; i<n; i++)
{
tmp = gcd(tmp,a[i]);
}
int x = maxn/tmp - n;
if(x%2==1)
printf("Alice\n");
else
printf("Bob\n");
return 0;
}
数学--数论--Alice and Bob (CodeForces - 346A )推导的更多相关文章
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- bzoj4730: Alice和Bob又在玩游戏
Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- sdutoj 2608 Alice and Bob
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2608 Alice and Bob Time L ...
- hdu 4268 Alice and Bob
Alice and Bob Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- 2014 Super Training #6 A Alice and Bob --SG函数
原题: ZOJ 3666 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 博弈问题. 题意:给你1~N个位置,N是最 ...
- ACdream 1112 Alice and Bob(素筛+博弈SG函数)
Alice and Bob Time Limit:3000MS Memory Limit:128000KB 64bit IO Format:%lld & %llu Submit ...
- 位运算 2013年山东省赛 F Alice and Bob
题目传送门 /* 题意: 求(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1) 式子中,x的p次方的系数 二进制位运算:p ...
- SDUT 2608:Alice and Bob
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...
随机推荐
- python学习 0 python简介
一.Python简介 python是一门简单易学又功能强大的编程语言.它具有高效的高级数据结构和简单而有效的面向对象编程的特性.python优雅的语法和动态类型.以及其解释性的性质,使它在许多领域和大 ...
- es实现mysql的like查询
es版本6.8 因为阿里云的dts同步最高支持es版本就是6.8 构建索引 PUT /z_test/ { "mappings": { "doc": { &quo ...
- Pytest系列(18)- 超美测试报告插件之allure-pytest的基础使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 官方介绍 Allure Frame ...
- hibernate.current_session_context_class 比较权威的解释
hibernate.current_session_context_class 博客分类: hibernate HibernateSpring多线程配置管理thread 遇到过的问题: 情景1: 在 ...
- Roles on a Machine Learning Project (机器学习项目中的角色)
原文 :https://medium.com/machine-learning-in-practice/roles-on-a-machine-learning-project-216903a6dc12 ...
- sws_接口自动化_demo
登录接口获取token: import requests import json def get_token(username, password): host = "https://sws ...
- Fiddler抓包过滤
1.User Fiters启用 2.Action Action:Run Filterset now是否运行,Load Filterset加载,Save Filterset保存: 3.Hosts过滤 Z ...
- 详解 Set接口
(请关注 本人"集合"总集篇博文--<详解 Collection接口>) 在Collection接口的子接口中,最重要的,也是最常见的两个-- List接口 和 Set ...
- python 基础篇 错误和异常处理
语法错误 所谓语法错误,也就是你写的代码不符合编程规范,无法被识别与执行,比如下面这个例子: if name is not None print(name) If 语句漏掉了冒号,不符合 Python ...
- Install go1.5 for CentOS7
https://golang.org/doc/install 下载好后,通过FTPS,传递到Linux里去,放哪里随便你自己,因为被墙了,所以在Windows通过旋风下载了这个玩意儿. 你也可以: w ...