CF#201 div2 C Alice and Bob(number theory)

来源:互联网 发布:上海数据交易中心 面试 编辑:程序博客网 时间:2024/06/05 00:54

地址

http://codeforces.com/contest/347/problem/C

题意

给n个数(2 ≤ n ≤ 100),a1, a2, …, an (1ai109),每个数不同。
每次可以从中取出两个数x,y,然后将 |x - y| ,加入到原来的数组中。
现在两个人来玩这个游戏,当其中一个人拿出任意两个数的差的绝对值都在原来的数组中,这个人就输了。
问最后谁赢。

解析

每个数的gcd,然后用其中最大的数/gcd就是用上规则能够凑成的数的数量,减掉n个数,然后判断奇偶就行了。

总结

如果早一点做过这题,大概沈阳那个签到题很快就能出了。。。

代码

#pragma comment(linker, "/STACK:1677721600")#include <map>#include <set>#include <cmath>#include <queue>#include <stack>#include <vector>#include <cstdio>#include <cstdlib>#include <cstring>#include <climits>#include <cassert>#include <iostream>#include <algorithm>#define pb push_back#define mp make_pair#define LL long long#define lson lo,mi,rt<<1#define rson mi+1,hi,rt<<1|1#define Min(a,b) ((a)<(b)?(a):(b))#define Max(a,b) ((a)>(b)?(a):(b))#define mem(a,b) memset(a,b,sizeof(a))#define FIN freopen("in.txt", "r", stdin)#define FOUT freopen("out.txt", "w", stdout)#define rep(i,a,b) for(int i=(a); i<=(b); i++)#define dec(i,a,b) for(int i=(a); i>=(b); i--)using namespace std;const int mod = 1e9 + 7;const double eps = 1e-8;const double ee = exp(1.0);const int inf = 0x3f3f3f3f;const int maxn = 1e6 + 10;const double pi = acos(-1.0);int readT(){    char c;    int ret = 0,flg = 0;    while(c = getchar(), (c < '0' || c > '9') && c != '-');    if(c == '-') flg = 1; else ret = c ^ 48;    while( c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c ^ 48);    return flg ? - ret : ret;}LL readTL(){    char c;    int flg = 0;    LL ret = 0;    while(c = getchar(), (c < '0' || c > '9') && c != '-');    if(c == '-') flg = 1; else ret = c ^ 48;    while( c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c ^ 48);    return flg ? - ret : ret;}LL gcd(LL a, LL b){    return b == 0 ? a : gcd(b, a % b);}int main(){    #ifdef LOCAL    FIN;    #endif // LOCAL    int n = readT();    LL d = readTL();    LL maxx = d;    rep(i, 1, n - 1)    {        LL t = readTL();        maxx = Max(t, maxx);        d = gcd(d, t);    }    LL num = maxx / d;    num -= n;    if (num % 2)    {        puts("Alice");    }    else    {        puts("Bob");    }    return 0;}
0 0