首页 > 其他分享 >题解:CodeForces 346A Alice and Bob[博弈/数论]

题解:CodeForces 346A Alice and Bob[博弈/数论]

时间:2024-07-14 14:55:03浏览次数:16  
标签:std __ set int 题解 CodeForces Alice Bob

CodeForces 346A

A. Alice and Bob

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 \(a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9)\) — 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).

Examples

input

2
2 3

output

Alice

input

2
5 3

output

Alice

input

3
5 6 7

output

Bob

Note

Consider the first test sample. Alice moves first, and the only move she can do is to choose \(2\) and \(3\), then to add \(1\) to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

我的题解

我的解法就是先找到里面所有数的最大公因数
然后用最大的数除以这个最大公因数
就能算出这个数组最多能有多少个数字
进而求出他们能放进来的数字的多少
进而推断出这个游戏的赢家

注意:
求最大公因数的时候
不要写

g = std::min(std::__gcd(a[i],a[j]),g);

一定要

g = std::__gcd(std::__gcd(a[i],a[j]),g);

前者是有问题的! 我已经WA了好多发了

我的代码

#include <bits/stdc++.h>
#define int long long

int t,n,num;

void solve()
{
    std::cin >> n;
    std::vector<int> a(n);
    for(int i = 0 ; i < n ; i ++){
        std::cin >> a[i];
    }

    std::sort(a.begin(),a.end());

    int g = std::__gcd(a[0],a[1]);
    for(int i = 0 ; i < n ; i ++)
    {
        for(int j = i ;j < n; j ++)
        {
            g = std::__gcd(std::__gcd(a[i],a[j]),g);
        }
    }

    if((a[n-1]/g - n)%2 == 0) std::cout << "Bob";
    else std::cout << "Alice";
}

signed main()
{
    solve();
    return 0;
}


有什么出现纰漏的地方还请大家在评论区指出!谢谢!

标签:std,__,set,int,题解,CodeForces,Alice,Bob
From: https://www.cnblogs.com/jiejiejiang2004/p/18301560

相关文章

  • 题解:CodeForces 843A Sorting by Subsequences[模拟/排序]
    CodeForces843AA.SortingbySubsequencestimelimitpertest:1secondmemorylimitpertest:256megabytesinputstandardinputoutputstandardoutputYouaregivenasequence\(a_1, a_2, ..., a_n\)consistingofdifferentintegers.Itisrequiredtos......
  • 题解:CodeForces 618C Constellation[贪心/模拟]
    CodeForces618CC.Constellationtimelimitpertest:2secondsmemorylimitpertest:256megabytesinputstandardinputoutputstandardoutputCatNokuhasobtainedamapofthenightsky.Onthismap,hefoundaconstellationwithnstarsnumberedfrom......
  • 题解:CodeForces 835 D Palindromic characteristics[区间dp/马拉车Manacher]
    CodeForces835DD.Palindromiccharacteristicstimelimitpertest:3secondsmemorylimitpertest:256megabytes*inputstandardinputoutputstandardoutputPalindromiccharacteristicsofstring\(s\)withlength\(|s|\)isasequenceof\(|s|\)in......
  • 题解:CodeForces 1019 A Elections[贪心/三分]
    CodeForces1019AA.Electionstimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputAsyouknow,majorityofstudentsandteachersofSummerInformaticsSchoolliveinBerlandforthemostparto......
  • [CF1941E] Rudolf and k Bridges 的题解
    题目大意在第\((i,j)\)个格子修建一个桥墩需要\(a_{i,j}+1\)的花费而且要求\((i,0)\)与\((i,m)\)必须修建桥墩并且桥墩之间的距离不得大于\(d\)。现在需要求见\(k\)个连续的桥,求最小代价。其中\(1\lek\len\le100,3\lem\le2\cdot10,1\led\lem\)。思路因为......
  • [ABC206E] Divide Both 的题解
    题目大意求出从\(l\)至\(r\)中满足以下条件的\((x,y)\)的个数。\(\gcd(x,y)\ne1\)且\(\gcd(x,y)\nex\)且\(\gcd(x,y)\ney\)。其中\(1\lel\ler\le10^6\)。思路正难则反,所以可以求出所有互质或者是相互倍数的\((x,y)\)的对数,在将其减去所有的方案数就是......
  • [CF1178D] Prime Graph 的题解
    题目大意构造一个简单无向图,是所有的有度的点的度都是质数而且总共的边的数量的个数是质数。思路因为需要让所有的入度都为质数,所以我们可以找到两个相邻的质数\(2,3\),因为这样即使增加了一条边那么这个节点的度也是质数。先将这个图构成一个巨大的环,接着如果所有的边数并不......
  • [CF1538F] Interesting Function 的题解
    题目大意给定两个正整数\(l,r\),将\(l\)不断加\(1\)直到\(l=r\),求出这一过程中\(l\)发生变化的位数总数。\(1\lel<r\le10^9\)。思路假设从\(l\)处理到\(r\)变化的次数为\(f(l,r)\)。因为直接求解出\(f(l,r)\)十分困难,所以可以通过求出\(f(0,l)\)......
  • 题解:CodeForces 1511 C Yet Another Card Deck[暴力/模拟]
    CodeForces1511CC.YetAnotherCardDeckDescriptionYouhaveacarddeckof\(n\)cards,numberedfromtoptobottom,i. e.thetopcardhasindex\(1\)andbottomcard —index\(n\).Eachcardhasitscolor:the\(i\)-thcardhascolor\(a_i\......
  • 「ABC217F」Make Pair 的题解
    题目大意一共\(2N\)个学生站成一排,其中有\(M\)对朋友关系。老师每次从队列中挑出两个相邻的学生作为同桌。为了关系和睦,每次选出的两个学生必须是朋友关系。选出的两个学生离开队列,空出来的位置左右合拢。请问老师有多少种方式选完所有学生?对于两种选人的方案,即使同桌关系相......