Codeforces 854 C Planning(优先队列+贪心)
来源:互联网 发布:mac 能玩魔兽争霸 编辑:程序博客网 时间:2024/05/20 06:22
题目地址
题意:有个机场他因为某些原因只能在时间k以后进行起飞,起飞的顺序是可以调的,只有一个限制就是不能延误之后的时间比正常起飞的时间好要早,每个航班没延误1分钟就要多花费ki块钱,问最小的花费。
思路:贪心的思想,每次选要花费最小的,然后对于限制条件的维护就是让大于m的在过来这个时间后再往里面添加。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 300010#define M 555005 #define LL __int64#define inf 0x3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;struct node { LL num; int id; friend bool operator <(node a, node b){ return a.num < b.num; }}fly[N], now;int times[N];int main() { cin.sync_with_stdio(false); int n, m; priority_queue<node> q; while (cin >> n >> m) { while (!q.empty()) { q.pop(); } for (int i = 1; i <= n; i++) { cin >> fly[i].num; fly[i].id = i; } LL sum = 0; LL ans = m + 1; for (int i = 1; i <= m; i++) { q.push(fly[i]); } while (!q.empty()) { if (ans <= n) q.push(fly[ans]); now = q.top(); q.pop(); LL id = now.id; times[id] = ans; sum += (ans - id)*fly[id].num; ans++; } cout << sum << endl; for (int i = 1; i <= n; i++) { cout << times[i] << " "; } cout << endl; } return 0;}
阅读全文
0 0
- Codeforces 854 C Planning(优先队列+贪心)
- [codeforces] 854C. Planning(优先队列)
- Codeforces Round #433 (Div. 2 C. Planning(优先队列)
- Codeforces 854C. Planning 贪心
- Codeforces Round #433 C. Planning(贪心)
- CodeForces 140C 贪心+优先队列
- CodeForces 137C【贪心+优先队列】
- Codeforces 854C Planning【贪心+并查集】
- Codeforces Round #433 (Div. 2) C. Planning(贪心)
- [CodeForces - 140C New Year Snowmen] 贪心 + STL 优先队列
- CodeForces 140 C. New Year Snowmen 详解 (贪心+优先队列)
- Codeforces Round #390 (Div. 2)(A,B,C(记忆化搜索),D(贪心,优先队列))
- (codeforces 853A)Planning 贪心
- CF322 C 优先队列+贪心
- Codeforces Round #433 (Div. 2, C. Planning (贪心+简单实现)
- Codeforces Round #433 (Div. 2)-贪心-C. Planning
- cf - 140 C. New Year Snowmen(贪心+优先队列)
- poj1042(贪心+优先队列)
- 关键词拍卖中最优保留价的研究
- Java常用数据结构
- 网口扫盲二:Mac与Phy组成原理的简单分析
- 170905 WarGames-Behemoth(3)
- Flex布局的属性
- Codeforces 854 C Planning(优先队列+贪心)
- 最常用的15大Eclipse开发快捷键技巧
- 基于微软案例数据挖掘之Microsoft 关联规则分析算法
- 网口扫盲三:以太网芯片MAC和PHY的关系
- Navicat 导入和导出 sql文件
- 1.6 开始第一幅“码绘”——运用算符和表达式,画出比例优美的懵逼脸
- oracle架构原理
- 判断某点是否在三角形内
- 整数划分问题