CodeForces 994B Knights of a Polygonal Table(STL、贪心)
http://codeforces.com/problemset/problem/994/B
题意:
给出n和m,有n个骑士,每个骑士的战力为ai,这个骑士有bi的钱,如果一个骑士的战力比另一个骑士的战力高,那么,他就可以夺取这个骑士的钱,但是每个骑士最多夺取m个人,问,这些骑士最多可以获得
多少钱。
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <algorithm>
- #include <vector>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <sstream>
- const int INF=0x3f3f3f3f;
- typedef long long LL;
- const int mod=1e9+;
- //const double PI=acos(-1);
- #define Bug cout<<"---------------------"<<endl
- const int maxn=1e5+;
- using namespace std;
- struct node
- {
- int val;
- int num;
- LL ans;
- int pos;
- }PE[maxn];
- bool cmp1(node a,node b)
- {
- return a.val<b.val;
- }
- bool cmp2(node a,node b)
- {
- return a.pos<b.pos;
- }
- int main()
- {
- int n,m;
- scanf("%d %d",&n,&m);
- for(int i=;i<=n;i++)
- {
- scanf("%d",&PE[i].val);
- PE[i].pos=i;
- }
- for(int i=;i<=n;i++)
- {
- scanf("%d",&PE[i].num);
- PE[i].ans=;
- }
- sort(PE+,PE++n,cmp1);//按战力排序
- priority_queue<int,vector<int> ,greater<int> > qe;//存放m个大的硬币数
- LL sum=;
- for(int i=;i<=n;i++)
- {
- if(qe.size()<m)
- {
- qe.push(PE[i].num);
- sum+=PE[i].num;
- }
- else if(!qe.empty())
- {
- int t=qe.top();
- if(t<PE[i].num)
- {
- qe.pop();
- sum=sum-t+PE[i].num;
- qe.push(PE[i].num);
- }
- }
- PE[i+].ans+=sum;//注意是i+1
- }
- sort(PE+,PE++n,cmp2);//按位置排序
- for(int i=;i<=n;i++)
- {
- printf("%lld ",PE[i].ans+PE[i].num);//注意是LL
- }
- return ;
- }
CodeForces 994B Knights of a Polygonal Table(STL、贪心)的更多相关文章
- Codeforces 994B. Knights of a Polygonal Table
解题思路 将骑士按力量从小到大排序,到第i个骑士的时候,前面的i-1个骑士他都可以击败,找出金币最多的k个. 用multiset存金币最多的k个骑士的金币数,如果多余k个,则删除金币数最小的,直到只有 ...
- [C++]Knights of a Polygonal Table(骑士的多角桌)
[程序结果:用例未完全通过,本博文仅为暂存代码之目的] /* B. Knights of a Polygonal Table url:http://codeforces.com/problemset/ ...
- 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 ...
- Knights of a Polygonal Table CodeForces - 994B (贪心)
大意:n个骑士, 每个骑士有战力p, 钱c, 每个骑士可以抢战力比他低的钱, 每个骑士最多抢k次, 对每个骑士求出最大钱数 按战力排序后, 堆维护动态前k大即可 #include <iostre ...
- [CF994B] Knights of a Polygonal Table - 贪心,堆
有 n 个骑士想决战.每个骑士都有能力值(互不相同),且身上带有一些金币.如果骑士 A 的能力值大于骑士 B ,那么骑士 A 就可以杀死骑士 B ,并获得骑士 B 身上的所有金币.但就算是骑士也不会残 ...
- 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 ...
- 【LA3523】 Knights of the Round Table (点双连通分量+染色问题?)
Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress ...
随机推荐
- tyvj 1860 后缀数组
真·模板题(然而还是TLE了,tyvj真是个毒瘤,输出double什么的就是 -0.00000000,这些就TLE2333) 简单的说一下本蒟蒻看了一天后缀数组的收获(这东西太神了,,,wcwc,,收 ...
- MyBatis 关联查询的实现:一对多
有2个实体:用户.订单,一个用户可以拥有多个订单,同时这多个订单属于一个用户,即一对多. user_tb: order_tb: 在“多”的一方(order)添加“一”的一方(user)的主键(user ...
- C#后台执行JavaScript
方法一: Page.RegisterClientScriptBlock 方法 命名空間: System.Web.UI 这个方法现在已经过时.改用ClientScriptManager.Register ...
- MySQL 插入 中文数据乱码解决
问题描述: 1.在命令行中进行插入,没有问题.但是显示存在部分乱码 2.在JDBC中插入成功.中文是直接以“??”形式显示. 通过Navicat客户端查看 与在网页中看到的一一致,说明读取没有问题,问 ...
- CTF -攻防世界-crypto新手区(1~4)
题目已经提示用base64直接解密就行 base64解密网址 http://tool.oschina.net/encrypt?type=3 题目提示是凯撒密码 http://www.zjslove.c ...
- 最短路问题--P4779 单源最短路(标准版)Dijkstra堆优化
题目背景 2018 年7月 19 日,某位同学在 NOI Day 1 T1 归程 一题里非常熟练地使用了一个广为人知的算法求最短路. 最终,他因此没能与理想的大学达成契约. 小 F 衷心祝愿大家不再重 ...
- vue整合外部js
vue引入外部jsimport { TrackLine } from "../../../../../static/js/trajectory.js";import { initM ...
- java数目
第一部分: Java语言篇1 <Java编程规范>星级:适合对象:初级,中级介绍:作者James Gosling(Java之父),所以这本书我觉得你怎么也得读一下.对基础讲解的很不错. 2 ...
- 树状数组--模版1和2 P3368、P3374
题目描述 如题,已知一个数列,你需要进行下面两种操作: 将某一个数加上 x 求出某区间每一个数的和 输入格式 第一行包含两个正整数 n,m,分别表示该数列数字的个数和操作的总个数. 第二行包含 n 个 ...
- 中小规模集群----Centos6部署wordpress及java程序
1 概述 1.1 业务需求 公司共有两个业务,网上图书馆和一个电商网站.现要求运维设计一个安全架构,本着高可用.廉价的原则. 具体情况如下: 网上图书馆是基于jsp开发: 电商系统是基于 ...