题目链接: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(贪心)的更多相关文章

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

    链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...

  2. Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...

  3. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors

    链接: https://codeforces.com/contest/1265/problem/E 题意: Creatnx has n mirrors, numbered from 1 to n. E ...

  4. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  5. Codeforces Round #604 (Div. 2) B. Beautiful Numbers

    链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...

  6. Codeforces Round #604 (Div. 2) A. Beautiful String

    链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...

  7. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...

  8. Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)

    题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...

  9. Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries

    题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...

随机推荐

  1. 【C++】《Effective C++》第三章

    第三章 资源管理 条款13:以对象管理资源 当申请一块动态内存时,可能会发生内存泄漏. class Investment {}; void f() { Investment* pInv = creat ...

  2. 搞定面试官:咱们从头到尾再说一次 Java 垃圾回收

    接着前几天的两篇文章,继续解析JVM面试问题,送给年后想要跳槽的小伙伴 万万没想到,面试中,连 ClassLoader类加载器 也能问出这么多问题..... 万万没想到,JVM内存区域的面试题也可以问 ...

  3. 计算机科学: 寄存器&内存

    参考: [十分钟速成课:计算机科学]6.寄存器&内存 要想聊寄存器Latch,首先要聊内存.什么是内存? Memory,就是储存信息的东西. 我们都玩过单机游戏,如果突然关机,游戏结束但是没有 ...

  4. 二 prometheus 监控 Redis

    Prometheus 监控Redis需要用到redis_exporter客户端, Prometheus -> redis_exporter这个模式, 类似监控Mysql 一个思路. 1 ) 设置 ...

  5. 立完flag,你可能需要对flag进行量化

    DevUI是一支兼具设计视角和工程视角的团队,服务于华为云DevCloud平台和华为内部数个中后台系统,服务于设计师和前端工程师. 官方网站:devui.design Ng组件库:ng-devui(欢 ...

  6. LeetCode559.N 叉树的最大深度

    题目 法一.层序遍历 1 class Solution { 2 public: 3 int maxDepth(Node* root) { 4 if(root== NULL) return 0; 5 q ...

  7. oracle rac与单实例DG切换

    1.主库查看状态(RAC库) SQL> select database_role,switchover_status from v$database; DATABASE_ROLE SWITCHO ...

  8. JVM(七)字符串详解

     常量池: 我们前面也一直说常量池有三种: 1:class文件中的常量池,前面我们解析class文件的时候解析的就是,这是静态常量池.在硬盘上. 2:运行时常量池.可以通过HSDB查看,是Instan ...

  9. Navicat 创建mysql存过、定时执行存过

    创建存过: 使用Navicat for MySQL工具创建存储过程步骤: 1. 新建函数(选择函数标签 -> 点击新建函数): 2.输入函数的参数个数.参数名.参数类型等: 3.编写存储过程: ...

  10. Bitter.Core系列九:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore 之 WITH 子句支持

    有时我们在聚合查询中,经常会有复杂的聚联查询.有时表的聚联查询SQL 子句比较复杂,DBA 会经常告诉们,能否通过WITH 子句优化.WITH 子句,是对SQL 聚联查询的优化.Bitter.Core ...