hdu 4546
来源:互联网 发布:阿里政务云 编辑:程序博客网 时间:2024/06/08 13:05
优先队列的应用, 求全排列的第m大。
参考 点击打开链接
注:自定义cmp的operator需返回值 类似
return x.now+c[x.pos]>y.now+c[y.pos];
#include<stdio.h>#include<string.h>#include<queue>#include<iostream>#include<algorithm>using namespace std;#define N 10005typedef __int64 LL;struct node{ LL now; int pos;}a;LL c[N];struct cmp { bool operator()(const node &x, const node &y) { return x.now+c[x.pos]>y.now+c[y.pos]; } };priority_queue < node, vector<node>, cmp > q; //最小值优先 int main(){ int n, m, tot, ca = 1; for(scanf("%d", &tot); tot--; ) { scanf("%d%d", &n, &m); for(int i = 0; i < n; i++) { scanf("%I64d", &c[i]); } sort(c, c + n); while(!q.empty()) q.pop(); a.now = 0, a.pos = 0; q.push(a); int ans = 0; while(m--) { if(q.empty()) break; node tep = q.top(); ans = tep.now + c[tep.pos++]; q.pop(); if(tep.pos < n) { q.push(tep); tep.now = ans; q.push(tep); } //printf("ans = %d\n", ans); } printf("Case #%d: %d\n", ca++, ans); } return 0;}
0 0
- hdu 4546
- hdu 4546
- hdu 4546 比赛难度
- HDU 4546 优先队列
- hdu 4546 比赛难度
- HDU 4546 比赛难度
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- Maple重点知识总结
- Codeforces Round #274 (Div. 2) C
- 获取POSIX线程真实PID/TID
- Android最佳实践之后台作业
- 老毛桃u盘装机怎么样?
- hdu 4546
- html target属性详解(如何分窗口,frame、target、base、hr)
- 批量安装系统工具cobbler配置
- 配置VIM编程和代码阅读环境
- Spring知识点梳理
- 柞滓谞锥兹坐装渍作作族着砖专篆坠宗撞
- 资钻追桌砖壮姿醉啄庄茁砖注咨锥鬃兹籽
- 【android笔记】android程序启动界面的编写
- 十一新疆之旅中邂逅的一首诗《黄河,母亲之河》