CF1472 D. Even-Odd Game

链接


传送门

概述

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值