CodeForces 346A Alice and Bob



规律是最大数减n,奇数则Alice,偶数则Bob
关键:最大数要先除以所有数的公约数

例如:

3

5 6 7

可以如下

Alice:1(7-6) 5 6 7

Bob:1 2(7-5) 5 6 7

Alice:1 2 3(5-2) 5 6 7

Bob:1 2 3 4(6-2) 5 6 7

轮到Alice了,但所有数两两绝对值都包含在内了,所以Alice输

如果

3

10 12 14

最后一组会是

Bob:2 4 6 8 10 12 14


所以需要预先求出所有数的最大公约数

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
LL a[110];
LL gcd (LL a,LL b) {
    if (a == 0) { return 0;}
    else { return (b == 0) ? a : gcd (b, a % b);}
}
int main() {
    int n; LL maxn=0; scanf ("%d",&n);
    for (int i=0; i<n; i++) {
        scanf ("%I64d",&a[i]);
        maxn=max (a[i],maxn);
    }
    LL ans=maxn;/*the largest one*/
    for (int i=0; i<n-1/*!*/; i++) {
        for (int j=i+1/*!*/; j<n; j++) {
            int t=gcd (a[i],a[j]);
            ans=gcd (ans,t);//gcd of all numbers
        }
    }
    printf ( ( ( (maxn/ans)-n) %2==1) ?"Alice\n":"Bob\n");
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值