传送门: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;
}