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