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

    最新文章

    1. MyBatis学习笔记(一)入门
    2. Canvas绘制时钟
    3. Nginx 开启gzip 压缩
    4. sublime Text及package control的安装
    5. 组合数学poj 1496 1850 同样的代码过两题
    6. Ecshop实现仿Taobao地区运费模板
    7. MySQL 查询数据
    8. QT5-控件-QLineEdit-文本输入控件,用来输入密码什么的还不错,可以和Linux登录一样不移动光标哦
    9. 02&mdash;从Cocos2DX视角看游戏组成
    10. 【WPF】获取电磁笔的压感
    11. 【二十五】cookie与session学习总结
    12. MongoDB 监控
    13. java压缩文件或文件夹并导出
    14. [外包]!采用asp.net core 快速构建小型创业公司后台管理系统(六.结语)
    15. net core webApi返回值
    16. python之多态与多态性
    17. eclipse中导入java类失败的问题
    18. navicat的下载、激活
    19. J01-Java IO流总结一 《异常捕获》
    20. sqllite 试图加载格式不正确的程序。 (异常来自 HRESULT:0x8007000B)

    热门文章

    1. HDU3336 Count the string(kmp
    2. 认识并学会springCloud的使用
    3. linux centos 7.3 编译安装mysql5.7
    4. linux连接Windows系统之项目连接
    5. python实现更换电脑桌面壁纸,锁屏,文件加密方式
    6. js实现复制内容到剪贴板
    7. 在CentOS 7系统下升级 Jenkins版本
    8. Codeforces Round #603 F Economic Difficulties
    9. O001、写在最前面
    10. subversion(SVN)服务配置及使用方法