您的位置:首页 > 其它

蓝书 LA 3135 优先队列入门

2017-01-17 22:04 316 查看

传送门:LA 3135

题解

优先对列入门运用

优先对列支持<重载, 可保持队列的有序性

AC code:

/*
File : 优先队列.cpp
Author : adrui
Lang : C++
*/
#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;

struct Node{
int t, num, p;
bool operator < (const Node& R) const{
if(t == R.t) return num > R.num;
return t > R.t;
}
};

int main(){
//freopen("in.txt", "r", stdin);
char s[30];
Node r;
int k;
priority_queue<Node> q;
while(cin >> s, s[0] != '#'){
cin >> r.num >> r.p;
r.t = r.p;
q.push(r);
}

cin >> k;

while(k--){
Node tmp = q.top();
q.pop();
cout << tmp.num << endl;
tmp.t += tmp.p;
q.push(tmp);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LA 优先对列 stl