首页 > 其他 > 详细

Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)

时间:2020-06-25 18:42:48      阅读:64      评论:0      收藏:0      [点我收藏+]

题目链接:https://codeforces.com/contest/1265/problem/C

题意

从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌,要求:

  • $g < s, g < b$
  • $g + s + d \le \lfloor \frac{n}{2} \rfloor$
  • 金牌队伍的过题数大于银牌,银牌队伍的过题数大于铜牌

输出颁发奖牌数最多的一种方案。

题解

根据第三个要求,奖牌一定是按过题数的大小颁发的。

金牌只颁发给过题最多数的队伍,可以使 $g < s, g < b$ 最容易满足。

接下来在保证 $g + s + d \le \lfloor \frac{n}{2} \rfloor$ 的前提下使 $g < s, g < b$ 即可。

代码

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        mp[x]++;
    }
    int g = 0, s = 0, b = 0;
    for (auto it = mp.rbegin(); it != mp.rend(); it++) {
        if (g + s + b + (*it).second <= n / 2) {
            if (g == 0)
                g = (*it).second;
            else if (s <= g)
                s += (*it).second;
            else
                b += (*it).second;
        } else break;
    }
    if (g < s and g < b)
        cout << g <<   << s <<   << b << "\n";
    else
        cout << 0 <<   << 0 <<   << 0 << "\n";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

 

Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)

原文:https://www.cnblogs.com/Kanoon/p/13192306.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!