LA 3135 Argus ( 优先队列 )
2013-03-09 17:08
239 查看
只有一组输入,每行三个数据,第一是指令,第二个是事件编号,第三个是这个事件发生的周期, 以“#”结束;然后输入k
输出前k个发生的事件,如果同时发生,标号小的先输出
代码:
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct item{
int qnum, per, time;
bool operator < ( const item& a ) const {
return time > a.time || ( time == a.time && qnum > a.qnum );
}
};
int main()
{
priority_queue <item> pq;
char s[20];
while ( scanf("%s", s) && s[0] != '#' ) {
item it;
scanf("%d%d", &it.qnum, &it.per );
it.time = it.per;
pq.push(it);
}
int k;
scanf("%d", &k);
while ( k-- ) {
item t = pq.top();
pq.pop();
printf("%d\n", t.qnum);
t.time += t.per;
pq.push(t);
}
}
输出前k个发生的事件,如果同时发生,标号小的先输出
代码:
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct item{
int qnum, per, time;
bool operator < ( const item& a ) const {
return time > a.time || ( time == a.time && qnum > a.qnum );
}
};
int main()
{
priority_queue <item> pq;
char s[20];
while ( scanf("%s", s) && s[0] != '#' ) {
item it;
scanf("%d%d", &it.qnum, &it.per );
it.time = it.per;
pq.push(it);
}
int k;
scanf("%d", &k);
while ( k-- ) {
item t = pq.top();
pq.pop();
printf("%d\n", t.qnum);
t.time += t.per;
pq.push(t);
}
}
相关文章推荐
- 优先队列 阿格斯(Argus Beijing La 3135)
- LA_3135优先队列
- LA_3135优先队列
- 指南 第三章 例题3 UVALive 3135 Argus(优先队列的应用)
- 蓝书 LA 3135 优先队列入门
- uva11997 K Smallest Sums&&UVALive 3135 Argus(优先队列,多路归并)
- 【优先队列之多路归并】UVALive 3135 Argus
- UVALive 3135--Argus+自己定义优先队列的优先规则
- LA_3135优先队列
- UVALive - 3135 - Argus (优先队列!!)
- UVALive - 3135 Argus【优先队列】
- UVALive 3135--Argus+自定义优先队列的优先规则
- I - Argus UVA - 1203 --优先队列
- Argus_优先队列_2018_2_19
- Argus , Beijing 2004 ,LA 3135
- UVALive3135 UVA1203 POJ2051 ZOJ2212 Argus【优先队列+优先搜索】
- LA 3135 Argus
- la 3135 Argus Data Structure
- LA - 3135 - Argus
- LA 3135 - Argus