Codeforces 853A Planning
题意
给出飞机单位晚点时间代价和原定起飞时间,现在前k分钟不能起飞,求付出的最小代价和起飞顺序
思路
构造两个优先队列q1,q2,q1按时间顺序,q2按代价顺序,初始将所有飞机入q1,将时间在k前的飞机从q1加入q2,然后按时间顺序取出q1加入q2,同时从q2取出代价最大的加入答案
代码
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int x = ,f= ; char ch = getchar();
while(ch<'' || ch>'') {if(ch == '-') f=-;ch = getchar();}
while(ch>=''&&ch<='') {x = x*+ch-'';ch = getchar();}
return x*f;
}
int n, k;
long long ans;
struct F{
long long t;
long long v;
int ans;
F(){}
F(int a,int b){
t = a, v = b;
}
}f[];
struct CMPT{
bool operator()(const F& a, const F& b){
return a.t>b.t;
}
};
struct CMPV{
bool operator()(const F& a, const F& b){
return a.v<b.v;
}
};
priority_queue<F, vector<F>, CMPT> qt;
priority_queue<F, vector<F>, CMPV> qv;
int main(){
scanf("%d%d",&n,&k);
for(int i = ;i<=n;i++) f[i] = F(i, read()), qt.push(f[i]);
while(qt.top().t<=k && !qt.empty()){
qv.push(qt.top());
qt.pop();
}
for(int i = k+;i<=k+n;i++){
if(!qt.empty()) qv.push(qt.top()), qt.pop();
ans += (i-qv.top().t)*qv.top().v, f[qv.top().t].ans = i;
qv.pop();
}
printf("%I64d\n",ans);
for(int i = ;i<=n;i++) printf("%d%s",f[i].ans,(i == n?"\n":" "));
return ;
}
Codeforces 853A Planning的更多相关文章
- CodeForces - 853A Planning (优先队列,贪心)
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...
- (codeforces 853A)Planning 贪心
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...
- codeforces 854C.Planning 【贪心/优先队列】
Planning time limit per test 1 second memory limit per test 512 megabytes input standard input outpu ...
- codeforce 853A Planning
题目地址:http://codeforces.com/problemset/problem/853/A 题目大意: 本来安排了 n 架飞机,每架飞机有 ci 的重要度, 第 i 架飞机的起飞时间为 i ...
- Codeforces 854C Planning 【贪心】
<题目链接> 题目大意: 表示有n架飞机本需要在[1,n]时间内起飞,一分钟只能飞一架.但是现在[1,k]时间内并不能起飞,只能在[k+1,k+n]内起飞.ci序号为i的飞机起飞延误一分钟 ...
- Codeforces 854C Planning(贪心+堆)
贪心:让代价大的尽量移到靠前的位置. 做法:先让前k个数加进堆里,枚举k+1~n+k,每次把新元素加进堆后找到最大代价放在当前位置即可. #include<bits/stdc++.h> # ...
- Planning CodeForces - 854C
Planning CodeForces - 854C 题意:有n架航班,第i架原先的时候是在第i分钟起飞的.现在前k分钟无法有飞机起飞,因此需要调整安排表,延后飞机起飞.仍然要求每一分钟只有一架飞机起 ...
- Codeforces div2 #499 B. Planning The Expedition 大水题
已经是水到一定程度了QAQ- Code: #include<cstdio> #include<algorithm> #include<cstring> using ...
- 【Codeforces Round #433 (Div. 2) C】Planning
[链接]h在这里写链接 [题意] 让你确定ti,使得∑(ti-i)*gi最小,其中ti∈[k+1..k+n],且每个ti都不能一样. 且ti>=i必须成立. [题解] 分解一下成为∑ti*gi ...
随机推荐
- ELK之在CentOS7.5上使用rpm包安装配置ELK7版本
一,安装环境查看 二,软件版本选用 jdk 1.8.0_171 elasticsearch 7.1.1 kibana 7.1.1 logstash 7.1.1 三,安装配置 1,安装JDK 过程不详述 ...
- 跟我学Shiro目录贴
转发地址:https://www.iteye.com/blog/jinnianshilongnian-2018398 扫一扫,关注我的公众号 购买地址 历经三个月左右时间,<跟我学Shiro&g ...
- java的mock工具:mockito
https://site.mockito.org https://github.com/mockito/mockito https://github.com/hehonghui/mockito-doc ...
- wordpress通过$wpdp更新数据表内容
如下面的代码 更新id为1的数据 table 指的是要更新的数据表 第一个数组 array( 'column1' => 'value1', 'column2' => 'value2' ) ...
- [转帖]8086 CPU 寄存器简介
8086 CPU 寄存器简介 https://www.cnblogs.com/BoyXiao/archive/2010/11/20/1882716.html 哎 没看完 感觉好复杂. 引子 打算写几篇 ...
- 【LOJ】#2210. 「HNOI2014」江南乐
LOJ#2210. 「HNOI2014」江南乐 感觉是要推sg函数 发现\(\lfloor \frac{N}{i}\rfloor\)只有\(O(\sqrt{N})\)种取值 考虑把这些取值都拿出来,能 ...
- Verilog整理
1.两种实例化 2.运算符//逻辑运算+按位运算//拼接运算符 3.reg默认为1位 4.{16{1}}与{16{1'b1}}不同 5.[1023:0] in ha[3:0]=(in>>( ...
- Python反射和内置方法(双下方法)
Python反射和内置方法(双下方法) 一.反射 什么是反射 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省).这一概念的提出很快引发 ...
- WUSTOJ 1889: 编辑距离(Java)
转自:
- Oracle常用基础语句(杂)
打开服务 WIN + R services.msc 登录 --方法1 --WIN + R --CMD sqlplus / as sysdba --方法2,常用 --WIN + R --CMD --&q ...