数学--数论--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 ...
随机推荐
- Java第五天,API常用类,静态(static)、集合(ArrayList)、日期(Date)、日历(Calendar)的使用方法
上文中我们学习到了Random随机数类和ArrayList<E>集合.这两个知识点都是经常用到的,那么除了这两个外,还有哪些知识点是我们所必须掌握的呢? static 使用static需要 ...
- MySQL REPLACE INTO 的使用
前段时间写游戏合服工具时出现过一个问题,源DB和目标DB角色表中主键全部都不相同,从源DB取出玩家数据再使用 replace into 写入目标DB中,结果总有几条数据插入时会导致目标DB中原有的角色 ...
- 合理使用CSS框架,加速UI设计进程
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 原文出处:https://dzone.com/articles/how-to-speed-up-your-d ...
- 采用TuesPechkin生成Pdf
1.需求 前段时间有个需求,要求把网页生成pdf,找了各种插件,才决定使用这个TuesPechkin,这个是后台采用C#代码进行生成 2.做法 我要做的是一个比较简单的页面,采用MVC绑定,数据动态加 ...
- 《深入理解 Java 虚拟机》笔记整理
正文 一.Java 内存区域与内存溢出异常 1.运行时数据区域 程序计数器:当前线程所执行的字节码的行号指示器.线程私有. Java 虚拟机栈:Java 方法执行的内存模型.线程私有. 本地方法栈:N ...
- coding++:都说新的Arraylist 扩容是(1.5倍+1) 看了1.8的源代码发现不是这么回事
都说新的Arraylist 扩容是(1.5倍+1) 看了1.8的源代码发现不是这么回事 就用下面这段代码在jdk的三个版本运行看了下效果: import java.lang.reflect.Fiel ...
- CSS盒模型属性详细介绍
一.概述 CSS盒模型是定义元素周围的间隔.尺寸.外边距.边框以及文本内容和边框之间内边距的一组属性的集合. 示例代码: <!DOCTYPE html> <html lang=&qu ...
- AJ学IOS 之ipad开发Popover的调色板应用_popover显示后其他控件仍然能进行交互
AJ分享,必须精品 一:效果 后面的是xcode的控制台 二:代码 ViewController #import "ViewController.h" #import " ...
- ASE project demo:pdf
欢迎使用 pdf ~ 主页面如下,整个app风格一致,保持简约舒适的视觉体验~ 侧边栏打开,可选择打开新的pdf文件,返回主页面,打开本地生词本,登录等操作~ 可以点击侧边栏OpenFile打开新的p ...
- Pie 杭电1969 二分
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...