【优先队列之多路归并】UVALive 3135 Argus
来源:互联网 发布:淘宝盖楼怎么才能中 编辑:程序博客网 时间:2024/05/21 17:39
UVALive 3135 Argus
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18684
题意
编写一个系统执行一系列Register命令:Register Q_num Period,每个命令执行周期是Period,执行事件Q_num;如果事件同时发生,优先执行Q_num小的。
示例
Sample Input
Register 2004 200
Register 2005 300
#
5
Sample Output
2004
2005
2004
2004
2005
思路
★ 典型多路合并问题,用优先队列维护将要发生的下一个事件,优先队列内容要事先定义优先级,总时间复杂度O(klogn)
参考代码
#include<bits/stdc++.h>using namespace std;const int _max = 2e4 + 10;char s[20];int n;struct Item{ int Q_num,Period,time; bool operator < (const Item &a) const{//const必不可少,解释优先级低 return (time > a.time) || (time == a.time && Q_num > a.Q_num); }};priority_queue<Item>pq;int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif // ONLINE_JUDGE Item item; while(scanf("%s",s) == 1 && s[0] != '#'){ scanf("%d%d",&item.Q_num,&item.Period); item.time = item.Period; pq.push(item); } scanf("%d",&n); for(int i = 0; i < n; ++ i){ item = pq.top(); //堆顶 pq.pop(); printf("%d\n",item.Q_num); item.time += item.Period;//更新下一个事件的时间 pq.push(item); } return 0;}
- 加粗
Ctrl + B
- 斜体
Ctrl + I
- 引用
Ctrl + Q
- 插入链接
Ctrl + L
- 插入代码
Ctrl + K
- 插入图片
Ctrl + G
- 提升标题
Ctrl + H
- 有序列表
Ctrl + O
- 无序列表
Ctrl + U
- 横线
Ctrl + R
- 撤销
Ctrl + Z
- 重做
Ctrl + Y
1 0
- 【优先队列之多路归并】UVALive 3135 Argus
- UVALive - 3135 Argus 优先队列
- UVALive - 3135 Argus 优先队列
- UVALive - 3135 Argus【优先队列】
- UVALive - 3135 - Argus (优先队列!!)
- UVALive 3135 Argus(优先队列)
- UVALive 3135 Argus(优先队列)
- UVALive 3135--Argus+自定义优先队列的优先规则
- LA 3135 argus(优先队列)
- LA 3135 Argus 优先队列
- Beijing 2004 / UVa 1203 / UVALive 3135 / ZOJ 2212 Argus (优先队列)
- 指南 第三章 例题3 UVALive 3135 Argus(优先队列的应用)
- LA 3135 Argus ( 优先队列 )
- 优先队列 POJ2051 Argus
- LA3135:Argus(优先队列)
- POJ2051 Argus 优先队列
- UVALive 3135 Argus
- UVALive 3135 Argus
- iScroll左右滑动阻止内容上下滑动 e.preventDefault() 解决办法
- tomcat memcached session 共享实现
- Ubuntu下VNC配置
- sh 获取 执行python的结果:$?
- [转载]正确使用Android性能分析工具——TraceView
- 【优先队列之多路归并】UVALive 3135 Argus
- POJ 1004 Financial Management
- Android学习笔记之Adapter
- Jquery_Ajax 注册验证(Struts2)<学习随笔>
- 类泛型及其泛型约束代码实例
- noip2002产生数 (高精*单精+深搜)
- LeetCode题解:Generate Parentheses
- 网络编程socket accept函数的理解
- apk安装 手机没sd卡安装失败解决方案