zoukankan      html  css  js  c++  java
  • Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)

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

    题意

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

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

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

    题解

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

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

    接下来在保证 $g + s + d le lfloor frac{n}{2} floor$ 的前提下使 $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 << "
    ";
        else
            cout << 0 << ' ' << 0 << ' ' << 0 << "
    ";
    }
    
    int main() {
        int t; cin >> t;
        while (t--) solve();
    }
  • 相关阅读:
    作业:ATM
    软件开发目录规范
    re模块
    logging模块
    ConfigParser模块&hashlib模块&subprocess模块
    json模块&pickle模块&shelve模块&xml模块
    时间模块time&datetime
    vue里面render详细写法
    node.js创建服务
    vue退出功能的实现
  • 原文地址:https://www.cnblogs.com/Kanoon/p/13192306.html
Copyright © 2011-2022 走看看