链接
概述
During their New Year holidays, Alice and Bob play the following game using an array 𝑎 of 𝑛 integers:
Players take turns, Alice moves first.
Each turn a player chooses any element and removes it from the array.
If Alice chooses even value, then she adds it to her score. If the chosen value is odd, Alice’s score does not change.
Similarly, if Bob chooses odd value, then he adds it to his score. If the chosen value is even, then Bob’s score does not change.
If there are no numbers left in the array, then the game ends. The player with the highest score wins. If the scores of the players are equal, then a draw is declared.
分析
Alice一定先选最大的数,我们用res表示Alice和Bob的分差,如果最大的是偶数,Alice得分,如果是奇数则防止Bob得分,对Bob也一样。
code
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
const int N = 2e5 + 10;
inline int read(){
int x = 0, op = 1; char ch = getchar();
while (!isdigit(ch)){if (ch == '-') op = -1;ch = getchar();}
while (isdigit(ch)){x = (x<<1)+(x<<3)+(ch^48); ch = getchar();}
return x * op;
}
inline void write(int x){
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
void solve(){
int n = read();
std::vector<int> v(n);
for (int &e : v) {
e = read();
}
std::sort(v.rbegin(), v.rend());
long long res = 0;
for (int i = 0; i < n; ++i) {
if (i % 2 == 0){
if (v[i] % 2 == 0) res += v[i];
}else{
if (v[i] % 2 == 1) res -= v[i];
}
}
if (res > 0){
printf("Alice\n");
}else if(res == 0){
printf("Tie\n");
}else{
printf("Bob\n");
}
}
int main(){
int cases = read();
while (cases--){
solve();
}
return 0;
}