C. Alice and Bob

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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).

大意:

n(n<=100)个正数,每次从中取任意两个数,他们的差值如果在集合中没有就加入集合中,问最后集合中元素个数的奇偶性?

思路:

快被自己蠢哭了。。。。竟然把题目读成了取出两个数,然后放回去。。。。。

首先,要明白一点,最终谁获胜,需要确定还缺几个数(还能够生成多少数)

  • 首先考虑只有两个数的情况,发现两个数x,y(x>y),可以观察到连续执行操作,可以生成的数的集合是

    {k∗gcd(x,y) | k=1,2,..且 k∗gcd(x,y)<=y}

  • 然后考虑有第三个数Z的情况,因为前面的两个数,极其生成的所有数的最大公约数都是gcd(x, y),
    所以加入第三个数之后这个集合的新的最大公约数是gcd(gcd(x,y),Z),然后生成集合是以这个最大公约数的倍数来生成.
  • ……..
  • 归纳到n个数,就是以最大的数为上界,所有n个数的最大公约数来填充的集合,元素个数为:

    max{xi | 1<=i<=n}gcd{x1,x2,...xn}

  • 代码:

    #include<bits/stdc++.h>
    using namespace std;
    const int MAXN=130;
    int a[MAXN];
    int gcd(int x,int y)
    {
    if(y==0) return x;
    return gcd(y,x%y);
    }
    int main()
    {
    int n;
    cin>>n;
    int m=-1;
    for(int i=0;i<n;i++){
    cin>>a[i];
    m=max(m,a[i]);
    }
    sort(a,a+n);
    int res=gcd(a[n-1],a[n-2]);
    for(int i=n-3;i>=0;i--){
    res=gcd(max(res,a[i]),min(res,a[i]));
    if(res==1) break;
    }
    int total=m/res-n;
    if(total%2) cout<<"Alice"<<endl;
    else cout<<"Bob"<<endl;
    }

    Codeforces Round #201.C-Alice and Bob的更多相关文章

    1. Educational Codeforces Round 9 B. Alice, Bob, Two Teams 前缀和

      B. Alice, Bob, Two Teams 题目连接: http://www.codeforces.com/contest/632/problem/B Description Alice and ...

    2. Codeforces Round #201 (Div. 2)C,E

      数论: C. Alice and Bob time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

    3. Codeforces Round #201 (Div. 2) - C. Alice and Bob

      题目链接:http://codeforces.com/contest/347/problem/C 题意是给你一个数n,然后n个数,这些数互不相同.每次可以取两个数x和y,然后可以得到|x - y|这个 ...

    4. codeforce Codeforces Round #201 (Div. 2)

      cf 上的一道好题:  首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是  所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...

    5. codeforces round #201 Div2 A. Difference Row

      #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

    6. Codeforces Round#201(div1) D. Lucky Common Subsequence

      题意:给定两个串,求出两个串的最长公共子序列,要求该公共子序列不包含virus串. 用dp+kmp实现 dp[i][j][k]表示以i结尾的字符串和以j结尾的字符串的公共子序列的长度(其中k表示该公共 ...

    7. Codeforces Round #201 (Div. 2). E--Number Transformation II(贪心)

      Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description You ar ...

    8. 数学--数论--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. ...

    9. Codeforces Round #557 (Div. 1) 简要题解

      Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...

    随机推荐

    1. Java第六周课堂示例总结

      一.如果一个类中既有初始化块,又有构造方法,同时还设定了字段的初始值,谁说了算? public class InitializeBlockDemo { /** * @param args */ pub ...

    2. CodeForces 820B + 821C

      (点击题目即可查看原题) 820B Mister B and Angle in Polygon  题意:在一个正n边形中,每个顶点按顺序记为1~n,正n边形中任意三点顶点组成一个角,∠x1x2x3,问 ...

    3. PHP 根据整数ID,生成唯一字符串

      //根据ID计算唯一邀请码 public static function createCode($Id){ static $sourceString = [ 0,1,2,3,4,5,6,7,8,9,1 ...

    4. mysql-1.1基础

      笔记内容:mysql基础,创建数据库,创建表,操作数据表,操作数据,简单查询,条件查询,排序,分组,聚合,连接查询(等值连接,内连接,外链接),子查询 自己提示:脑图笔记存于网盘中  右键:新标签页打 ...

    5. Docker 数据卷与容器互联

      Docker是基于Go语言实现的开源容器项目,Docker让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制, ...

    6. redis 学习(13)-- BitMap

      BitMap 什么是 BitMap BitMap,即位图,其实也就是 byte 数组,用二进制表示,只有 0 和 1 两个数字. 如图所示: 重要 API 命令 含义 getbit key offse ...

    7. 通过Nginx对CC攻击限流

      最近公司部署到阿里金融云的系统遭受CC攻击,网络访问安全控制仅靠阿里云防火墙保障,在接入层及应用层并未做限流. 攻击者拥有大量的IP代理,只要合理控制每个IP的请求速率(以不触发防火墙拦截为限),仍给 ...

    8. sklearn学习小结

      机器学习的一般流程: 1.获取数据 2.数据预处理 3.数据集分拆 4.搭建模型 5.模型评估 6.模型保存 7.模型优化 接下来,以Sklearn为例,一一介绍. 1.获取数据 1.1.导入数据集: ...

    9. Linux系统文件系统及文件基础篇

      学习Linux,重难点在于掌握不同类别的文件系统及其作用.通过对Linux系统的安装,我们首先来了解下Linux系统里各个目录文件夹下的大致功能:主要的目录树的有/./root./home./usr. ...

    10. java8学习之流的短路与并发流

      并发流: 从api的角度来看,其实跟咱们之前一直在用的stream()方式差不多,但是底层是有明显的不同,所以这里初步先对并发流有一个基本的认识, 说到串行与并行,最直观的感受就是效率的不同,所以下面 ...