Knights of a Polygonal Table CodeForces - 994B (贪心)
大意:n个骑士, 每个骑士有战力p, 钱c, 每个骑士可以抢战力比他低的钱, 每个骑士最多抢k次, 对每个骑士求出最大钱数
按战力排序后, 堆维护动态前k大即可
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- #include <queue>
- #define REP(i,a,n) for(int i=a;i<=n;++i)
- using namespace std;
- typedef long long ll;
- const int N = 2e5+10;
- int n, m, k;
- ll sum, a[N];
- struct _ {int p, c, id;}q[N];
- priority_queue<int,vector<int>,greater<int> > s;
- int main() {
- s.push(0x7fffffff);
- scanf("%d%d", &n, &k);
- REP(i,1,n) scanf("%d",&q[i].p),q[i].id=i;
- REP(i,1,n) scanf("%d",&q[i].c);
- sort(q+1,q+1+n,[](_ a,_ b) {return a.p<b.p;});
- REP(i,1,n) {
- a[q[i].id] = sum+q[i].c;
- if (s.size()<=k) s.push(q[i].c),sum+=q[i].c;
- else if (s.top()<q[i].c) {
- sum += q[i].c-s.top();
- s.pop();s.push(q[i].c);
- }
- }
- REP(i,1,n) printf("%lld ", a[i]);
- puts("");
- }
Knights of a Polygonal Table CodeForces - 994B (贪心)的更多相关文章
- CF994B Knights of a Polygonal Table 第一道 贪心 set/multiset的用法
Knights of a Polygonal Table time limit per test 1 second memory limit per test 256 megabytes input ...
- [C++]Knights of a Polygonal Table(骑士的多角桌)
[程序结果:用例未完全通过,本博文仅为暂存代码之目的] /* B. Knights of a Polygonal Table url:http://codeforces.com/problemset/ ...
- CodeForces 994B Knights of a Polygonal Table(STL、贪心)
http://codeforces.com/problemset/problem/994/B 题意: 给出n和m,有n个骑士,每个骑士的战力为ai,这个骑士有bi的钱,如果一个骑士的战力比另一个骑士的 ...
- Codeforces 994B. Knights of a Polygonal Table
解题思路 将骑士按力量从小到大排序,到第i个骑士的时候,前面的i-1个骑士他都可以击败,找出金币最多的k个. 用multiset存金币最多的k个骑士的金币数,如果多余k个,则删除金币数最小的,直到只有 ...
- [CF994B] Knights of a Polygonal Table - 贪心,堆
有 n 个骑士想决战.每个骑士都有能力值(互不相同),且身上带有一些金币.如果骑士 A 的能力值大于骑士 B ,那么骑士 A 就可以杀死骑士 B ,并获得骑士 B 身上的所有金币.但就算是骑士也不会残 ...
- Arthur and Table CodeForces - 557C
Arthur and Table CodeForces - 557C 首先,按长度排序. 长度为p的桌腿有a[p]个. 要使得长度为p的桌腿为最长,那么要按照代价从小到大砍掉sum{长度不到p的腿的数 ...
- POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 12439 Acce ...
- POJ 2942 Knights of the Round Table
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 10911 Acce ...
- poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 9169 Accep ...
随机推荐
- Linux服务器---网络配置
禁止ping 有些时候为了保护主机,会禁止其他机器对主机进行ping操作.Ping命令用的是ICMP协议,只要禁用ICMP协议,那么ping方法就无法检测这台主机.关于ICMP协议的配置文件是“/pr ...
- python3.4学习笔记(九) Python GUI桌面应用开发工具选择
python3.4学习笔记(九) Python GUI桌面应用开发工具选择 Python GUI开发工具选择 - WEB开发者http://www.admin10000.com/document/96 ...
- mybatis项目启动报错 The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
启动项目报错 2018-02-26 17:09:51,535 ERROR [org.springframework.web.context.ContextLoader] - Context initi ...
- oracle计算过程执行时间写法
--在oracle写过程中很多是对数据处理,业务比较繁琐,有的需要结合job定时器使用,这样就需要知道执行过程的大概时间,不废话直接上脚本,统计单位为分钟 PROCEDURE DATA_DEAL_WI ...
- 05: 配置yum源
1.1 将镜像复制到本地创建yum源 1.将准备好的系统镜像放到指定的目录,本次目录指定在:/dawnfs/sourcecode 2.创建挂载目录:mkdir /mnt/yum 3.挂载镜像: mou ...
- 如何让VS2012编写的程序在XP下运行
Win32主程序需要以下设置 第一步:在工程属性General设置 第二步:在C/C++ Code Generation 设置 第三步:SubSystem 和 Minimum Required Ve ...
- 过滤Windows文件名中的非法字符
转载:http://blog.csdn.net/infoworld/article/details/42033097 场景: 1. 通常生成文件时需要一个文件名,而生成文件名的方式可能是通过用户输入的 ...
- 25个c#知识点
网站地址:http://m.3y.uu456.com/mbp_56hl91r1rx5uqa87qrzo_1.html
- 又一个改写MBR的病毒(TDSS TDL4)
此毒为TDSS TDL4 的又一个变种.RIS2011 目前尚未收录此毒.此毒的主要行为是改写MBR,并在硬盘尾部的190个扇区内写入病毒代码.病毒的上述动作可穿透还原类软件对系统的保护.我在Acro ...
- 【入门详解】MyBatis入门基础详解
什么是mybatis? MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBatis使用简单的XM ...