zoukankan      html  css  js  c++  java
  • 【Codeforces Round #693 (Div. 3) D】Even-Odd Game

    题目链接

    链接

    翻译

    translation

    题解

    贪心,随便想想也能猜到,排序。然后哪一方最大的数字大(奇数和偶数),就抢对方的(对方的奇偶性数字大),或者拿自己的(自己的奇偶性大)。

    这样,对于拿的那个人来说收益总是最大的。

    不够了就随遇而安就行。。

    代码

    #include <bits/stdc++.h>
    #define lson l,mid,rt*2
    #define rson mid+1,r,rt*2+1
    #define LL long long
    using namespace std;
    
    const int N = 2e5;
    
    int n;
    int a[N+10],b[2][N+10];
    LL f[N+10];
    
    int main(){
        ios::sync_with_stdio(0),cin.tie(0);
        int T;
        cin >> T;
        while (T--){
            cin >> n;
            int cnt[2];
            cnt[0] = cnt[1] = 0;
            for (int i = 1;i <= n; i++){
                cin >> a[i];
                int o = a[i]%2;
                cnt[o]++;
                b[o][cnt[o]] = a[i];
            }
            for (int i = 0;i < 2; i++){
                sort(b[i]+1,b[i]+1+cnt[i]);
            }
            LL scoreAlice = 0,scoreBob = 0;
            for (int i = 1;i <= n; i++){
                if (i%2==1){
                    //Alice turn he like even
                    if (cnt[0] == 0){
                        cnt[1]--;
                        continue;
                    }
                    if (cnt[1] == 0 || b[0][cnt[0]]>=b[1][cnt[1]]){
                        scoreAlice+=b[0][cnt[0]];
                        cnt[0]--;
                    }else{
                        cnt[1]--;
                    }
                }else{
                    if (cnt[1] == 0){
                        cnt[0]--;
                        continue;
                    }
                    if (cnt[0] == 0 || b[1][cnt[1]]>=b[0][cnt[0]]){
                        scoreBob+=b[1][cnt[1]];
                        cnt[1]--;
                    }else{
                        cnt[0]--;
                    }
                }
            }
            if (scoreAlice==scoreBob){
                cout <<"Tie"<<endl;
            }else if (scoreAlice>scoreBob){
                cout <<"Alice"<<endl;
            }else{
                cout <<"Bob"<<endl;
            }
        }
        return 0;
    }
    
  • 相关阅读:
    7. 整数反转
    14. 最长公共前缀
    13. 罗马数字转整数
    从web解析到网络空间
    python实例:霍兰德人格分析雷达图
    从数据处理到人工智能
    Python第三方库的安装
    Python之os库的使用
    Python第三方库的安装
    Python程序设计思维
  • 原文地址:https://www.cnblogs.com/AWCXV/p/14239842.html
Copyright © 2011-2022 走看看