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\) ...
随机推荐
- 2021年了,`IEnumerator`、`IEnumerable`还傻傻分不清楚?
IEnumerator.IEnumerable这两个接口单词相近.含义相关,傻傻分不清楚. 入行多年,一直没有系统性梳理这对李逵李鬼. 最近本人在怼着why神的<其实吧,LRU也就那么回事> ...
- #2020征文-开发板#使用Python开发鸿蒙应用--2021.01.07直播图文
写在前面: 每年的过年前夕,手中的项目一定会告急...而自己又缺乏三头六臂七十二变等特技,所以只能在鸿蒙社区先消失一阵子了.今天再看社区的帖子,发现大家的进步可不一般,各种案例示例层出不穷,一片欣欣向 ...
- 通过写n本书的积累,我似乎找到了写好技术文章的方法(回复送我写的python股票电子书)
我写的书不算少,写的博文就更多了,但大多数书的销量也就一般,而我写的技术文章里,虽然也有点击过万的,但不少点击量也就只有三位数. 通过不断反思,也通过对比了一些畅销书和顶流文章,我似乎找到了一些原因, ...
- pip不是内部或外部命令解决方法
问题 已经配置好Python环境,但是安装依赖时,出现pip不是内部或外部命令. 解决方法 找到pip.exe文件所在的目录,将所在路径配置到环境变量path中. 再次输入pip
- 断言封装之key检查及kv实战示例
️️️️️️️️️️️️️️️️️️️️️️️️️️️️️ 测试: 断言处理: demo_04.pyimport jsonjson_obj = {"access_token":&q ...
- (二)数据源处理5-excel数据转换实战(上)
把excel_oper02.py 里面实现的:通过字典的方式获取所有excel数据.放进utils: ️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️ utils: def get_al ...
- 【Git】4、创建代码仓库,HTTP、SSH拉取远端代码
拉取远端代码:使用Git命令下载远程仓库到本地 文章目录 拉取远端代码:使用Git命令下载远程仓库到本地 1.创建远程代码仓库 2.创建仓库 3.进入仓库 4.HTTP(S)获取远程仓库 首次拉取 更 ...
- Git软件安装过程
Git程序安装过程 官网: https://git-scm.com/ 下载: https://git-scm.com/downloads 我的操作系统是 Windows + 64位的 https:// ...
- Ubuntu Terminal命令行新建仓库并推送到远程仓库
通常情况下,在本地新建一个仓库之后,需要在远端网页端也新建一个空的同名仓库,然后将两者进行关联才能推送. 那有没有办法直接在命令行就完成从新建到推送的过程而不需要中间在网页端也操作一番呢?办法当然是有 ...
- SAP中的密码输入框
在SAP中的密码输入框,可分为两种情况: 1.用selection语句书写的选择屏幕上的密码输入框 实现的方式就是在AT SELECTION-SCREEN OUTPUT事件中写入如下代码: LOOP ...