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. 爬取糗事百科热门段子的数据并保存到本地,xpath的使用

      和之前的爬虫类博客的爬取思路基本一致: 构造url_list,因为糗事百科的热门栏目默认是13页,所以这个就简单了 遍历发送请求获取响应 提取数据,这里用的是xpath提取,用的是Python的第三方 ...

    2. go语言坑之并发访问map

      fatal error: concurrent map read and map write 并发访问map是不安全的,会出现未定义行为,导致程序退出.所以如果希望在多协程中并发访问map,必须提供某 ...

    3. Linux实用命令及技巧

      1.  查看CPU及内存使用排行 1)查看当前CPU及内存的整体使用情况 top 2)可以使用以下命令查使用内存最多的10个进程 ps -aux | sort -k4nr | head -n 10 3 ...

    4. VMware中centos7访问外网配置

      1.配置虚拟机网络适配器,选择NAT模式 2.在编辑->虚拟机网络编辑器->更改设置 选择目前使用的网卡 3.通过ifconfig查看网卡配置 4.编辑网络配置对应上面网卡名称ens33 ...

    5. 北大 ACM highways问题研究(最小生成树)

      #include<stdlib.h> #include<stdio.h> #include<queue> struct vertex//代表一个村庄 { int m ...

    6. Intel Coleto Creek SSL chipset

      Intel Coleto Creek SSL chipset name type interface speed model SR-IOV driver Intel SSL chipset Colet ...

    7. Charles学习(三)之使用Map local代理本地静态资源以及配置网页代理在Mac模拟器调试iOS客户端

      前言 问题一:我们在App内嵌H5开发的过程中,肯定会遇到一个问题就是我不想在chrome的控制台中调试,我想要在手机上调试,那么如何解决这个问题呢? 问题二:我们期待调试时达到的效果就是和Charl ...

    8. Spring的基本应用(1):IDEA版本

      一.Spring概述: 1.什么是Spring? Spring是分层的JavaSE/EE应用full-stack(一站式)轻量级开源框架,以IoC(Inverse Of Control:控制反转)和A ...

    9. python 写入JSON中文乱码解决方法

      在将一个字典添加入json中时多加入一个参数就可以了 json.dumps(dict(item), ensure_ascii=False) 例子 with open('zh-cn.json','w', ...

    10. zabbix分布式部署和主机自动发现

      1.分布式部署原理 1.1Zabbix分布式部署的原理 传统的部署架构,是server直接监控所有的主机,全部主机的数据都是有server自己来采集和处理,server端的压力比较大,当监控主机数量很 ...