http://codeforces.com/problemset/problem/994/B

题意:

给出n和m,有n个骑士,每个骑士的战力为ai,这个骑士有bi的钱,如果一个骑士的战力比另一个骑士的战力高,那么,他就可以夺取这个骑士的钱,但是每个骑士最多夺取m个人,问,这些骑士最多可以获得

多少钱。

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iostream>
  4. #include <string>
  5. #include <math.h>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <stack>
  9. #include <queue>
  10. #include <set>
  11. #include <map>
  12. #include <sstream>
  13. const int INF=0x3f3f3f3f;
  14. typedef long long LL;
  15. const int mod=1e9+;
  16. //const double PI=acos(-1);
  17. #define Bug cout<<"---------------------"<<endl
  18. const int maxn=1e5+;
  19. using namespace std;
  20.  
  21. struct node
  22. {
  23. int val;
  24. int num;
  25. LL ans;
  26. int pos;
  27. }PE[maxn];
  28.  
  29. bool cmp1(node a,node b)
  30. {
  31. return a.val<b.val;
  32. }
  33.  
  34. bool cmp2(node a,node b)
  35. {
  36. return a.pos<b.pos;
  37. }
  38.  
  39. int main()
  40. {
  41. int n,m;
  42. scanf("%d %d",&n,&m);
  43. for(int i=;i<=n;i++)
  44. {
  45. scanf("%d",&PE[i].val);
  46. PE[i].pos=i;
  47. }
  48. for(int i=;i<=n;i++)
  49. {
  50. scanf("%d",&PE[i].num);
  51. PE[i].ans=;
  52. }
  53. sort(PE+,PE++n,cmp1);//按战力排序
  54. priority_queue<int,vector<int> ,greater<int> > qe;//存放m个大的硬币数
  55. LL sum=;
  56. for(int i=;i<=n;i++)
  57. {
  58. if(qe.size()<m)
  59. {
  60. qe.push(PE[i].num);
  61. sum+=PE[i].num;
  62. }
  63. else if(!qe.empty())
  64. {
  65. int t=qe.top();
  66. if(t<PE[i].num)
  67. {
  68. qe.pop();
  69. sum=sum-t+PE[i].num;
  70. qe.push(PE[i].num);
  71. }
  72. }
  73. PE[i+].ans+=sum;//注意是i+1
  74. }
  75. sort(PE+,PE++n,cmp2);//按位置排序
  76. for(int i=;i<=n;i++)
  77. {
  78. printf("%lld ",PE[i].ans+PE[i].num);//注意是LL
  79. }
  80. return ;
  81. }

CodeForces 994B Knights of a Polygonal Table(STL、贪心)的更多相关文章

  1. Codeforces 994B. Knights of a Polygonal Table

    解题思路 将骑士按力量从小到大排序,到第i个骑士的时候,前面的i-1个骑士他都可以击败,找出金币最多的k个. 用multiset存金币最多的k个骑士的金币数,如果多余k个,则删除金币数最小的,直到只有 ...

  2. [C++]Knights of a Polygonal Table(骑士的多角桌)

    [程序结果:用例未完全通过,本博文仅为暂存代码之目的] /* B. Knights of a Polygonal Table url:http://codeforces.com/problemset/ ...

  3. 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 ...

  4. Knights of a Polygonal Table CodeForces - 994B (贪心)

    大意:n个骑士, 每个骑士有战力p, 钱c, 每个骑士可以抢战力比他低的钱, 每个骑士最多抢k次, 对每个骑士求出最大钱数 按战力排序后, 堆维护动态前k大即可 #include <iostre ...

  5. [CF994B] Knights of a Polygonal Table - 贪心,堆

    有 n 个骑士想决战.每个骑士都有能力值(互不相同),且身上带有一些金币.如果骑士 A 的能力值大于骑士 B ,那么骑士 A 就可以杀死骑士 B ,并获得骑士 B 身上的所有金币.但就算是骑士也不会残 ...

  6. POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 12439   Acce ...

  7. POJ 2942 Knights of the Round Table

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 10911   Acce ...

  8. poj 2942 Knights of the Round Table 圆桌骑士(双连通分量模板题)

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 9169   Accep ...

  9. 【LA3523】 Knights of the Round Table (点双连通分量+染色问题?)

    Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress ...

随机推荐

  1. tyvj 1860 后缀数组

    真·模板题(然而还是TLE了,tyvj真是个毒瘤,输出double什么的就是 -0.00000000,这些就TLE2333) 简单的说一下本蒟蒻看了一天后缀数组的收获(这东西太神了,,,wcwc,,收 ...

  2. MyBatis 关联查询的实现:一对多

    有2个实体:用户.订单,一个用户可以拥有多个订单,同时这多个订单属于一个用户,即一对多. user_tb: order_tb: 在“多”的一方(order)添加“一”的一方(user)的主键(user ...

  3. C#后台执行JavaScript

    方法一: Page.RegisterClientScriptBlock 方法 命名空間: System.Web.UI 这个方法现在已经过时.改用ClientScriptManager.Register ...

  4. MySQL 插入 中文数据乱码解决

    问题描述: 1.在命令行中进行插入,没有问题.但是显示存在部分乱码 2.在JDBC中插入成功.中文是直接以“??”形式显示. 通过Navicat客户端查看 与在网页中看到的一一致,说明读取没有问题,问 ...

  5. CTF -攻防世界-crypto新手区(1~4)

    题目已经提示用base64直接解密就行 base64解密网址 http://tool.oschina.net/encrypt?type=3 题目提示是凯撒密码 http://www.zjslove.c ...

  6. 最短路问题--P4779 单源最短路(标准版)Dijkstra堆优化

    题目背景 2018 年7月 19 日,某位同学在 NOI Day 1 T1 归程 一题里非常熟练地使用了一个广为人知的算法求最短路. 最终,他因此没能与理想的大学达成契约. 小 F 衷心祝愿大家不再重 ...

  7. vue整合外部js

    vue引入外部jsimport { TrackLine } from "../../../../../static/js/trajectory.js";import { initM ...

  8. java数目

    第一部分: Java语言篇1 <Java编程规范>星级:适合对象:初级,中级介绍:作者James Gosling(Java之父),所以这本书我觉得你怎么也得读一下.对基础讲解的很不错. 2 ...

  9. 树状数组--模版1和2 P3368、P3374

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 将某一个数加上 x 求出某区间每一个数的和 输入格式 第一行包含两个正整数 n,m,分别表示该数列数字的个数和操作的总个数. 第二行包含 n 个 ...

  10. 中小规模集群----Centos6部署wordpress及java程序

      1    概述 1.1   业务需求 公司共有两个业务,网上图书馆和一个电商网站.现要求运维设计一个安全架构,本着高可用.廉价的原则. 具体情况如下: 网上图书馆是基于jsp开发: 电商系统是基于 ...