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} \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(贪心)的更多相关文章
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- Codeforces Round #604 (Div. 2) A. Beautiful String(贪心)
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母 ...
- 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 ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- 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 ...
- Codeforces Round #604 (Div. 2) A. Beautiful String
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecu ...
- Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学
题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)
题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...
- Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries
题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...
随机推荐
- 如何优雅的传递 stl 容器作为函数参数来实现元素插入和遍历?
问题背景 开始正文之前,做一些背景铺垫,方便读者了解我的工程需求.我的项目是一个客户端消息分发中心,在连接上消息后台后,后台会不定时的给我推送一些消息,我再将它们转发给本机的其它桌面产品去做显示.后台 ...
- Flutter 布局类组件:流式布局(Wrap和Flow)
前言 把超出屏幕显示范围会自动折行的布局称为流式布局.Flutter中通过Wrap和Flow来支持流式布局,将Row换成Wrap后溢出部分则会自动折行. Wrap 接口描述 Wrap({ Key ke ...
- 解决Tengine健康检查引起的TIME_WAIT堆积问题
简介: 解决Tengine健康检查引起的TIME_WAIT堆积问题 一. 问题背景 "服务上云后,我们的TCP端口基本上都处于TIME_WAIT的状态"."这个问题在线下 ...
- IDEA安装codota插件和使用,开发人员的知心伙伴
打开IDEA 点击左上角的File之后,如下图 成功后如图所示
- 5V 升压 8.4V,5V 转 8.4V 做两节锂电池充电芯片
5V 升压 8.4V SOT23-6 封装的六脚升压 IC PW5300 是一颗 DC-DC 异步整流升压转换器芯片,输入电压范围 2.6V-5.5V.最高输出 电压 12V, PW5300 是一种电 ...
- linux自定义位置安装tomcat8.5
1 下载tomcat安装文件 下载地址:https://tomcat.apache.org/download-80.cgi 2 解压文件 tar -zxvf apache-tomcat-8.5.56 ...
- 转 jmeter录制https请求
jmeter录制https请求 文章转自:https://www.cnblogs.com/zhengna/p/10180998.html 工具:Jmeter4.0 + Java1.8 需求:对某ht ...
- Vue之优化封装请求方法
Vue之优化封装请求方法 对于代码中的请求操作 1.接口请求可能需要重用 2.实际工作中,接口非常容易变动, 改起来很麻烦! 我们建议的做法是把所有的请求都封装成函数然后统一的>###组织到模块 ...
- Django 模型(数据库)-cmd下的操作
Django 模型是与数据库相关的,与数据库相关的代码一般写在 models.py 中,Django 支持 sqlite3, MySQL, PostgreSQL等数据库,只需要在settings.py ...
- threading.RLock()
# Copyright 2001-2017 by Vinay Sajip. All Rights Reserved.## Permission to use, copy, modify, and di ...