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 ...
随机推荐
- UVA - 1605 Building for UN (联合国大楼)
题意:一个联合国大楼每层都有数量相等大小相同的格子,将其分配给n个国家,使任意两个不同的国家都相邻(同层有公共边或相邻层的同一个格子). 分析:可以设计一个只有两层的大楼,第一层每个国家占一行,第二层 ...
- windows driver 枚举串口
//枚举串口 NTSTATUS status; HANDLE hKey = NULL; OBJECT_ATTRIBUTES oa; UNICODE_STRING strPath = RTL_CONST ...
- FreeImage库的学习和使用
1.FreeImage_SetPixelColor x横轴方向 y纵轴方向 左下角是(0, 0)
- 2.11 DataBinding 简单使用
DataBindIng 在我理解看来类似于其他语言当中的全局变量,只修改一处就可全部修改 添加位置和代码如下: 打开DataBinding 开关: dataBinding { enabled true ...
- MVC学生管理系统-阶段V(模糊查询)
项目源码 :https://download.csdn.net/download/weixin_44718300/11091042 此处省略一段话.去上一篇查看 NO01:修改list.jsp < ...
- JZOJ-2019-11-7 A组
T1 Input 从文件 awesome.in 中读入数据. 第一行 2 个用空格隔开的整数 \(n\), \(P\). 第二行 n 个用空格隔开的整数 \(A_1, \cdots , A_n\). ...
- zabbix安装及配置
一.安装zabbix_server 二.安装zabbix_agent 三.zabbix配置详解
- Maven:Eclipse导入从SVN上检出的Maven多模块工程
大致步骤: 1.从SVN中检出多模块项目,名称随意(Eclipse中可以在[Window ==>>Show View==>>Other==>>SVN==>&g ...
- .NET core ABP 获取远程IP地址
2.asp.net core 2.x上配置 第一步:在控制器中定义变量 private IHttpContextAccessor _accessor; 第二步: 控制器的构造函数进行注入 public ...
- 直击JDD | 共建智能新城 京东云让城市生活变得简单美好
技术快速革新,创新持续激发.在"智能+"时代,云计算.大数据.5G等新技术,已成为社会生产方式变革.创新人类生活空间的重要力量--11月19日,JDD-2019京东全球科技探索者大 ...