UVALive - 3135 Argus——优先队列

#include 
#include 
#include 
#include 
#include 
using namespace std;
struct Date {
    int val, id, add;
    Date(int x, int y, int z) : val(x), id(y), add(z) {}
    bool operator < (const Date &temp) const {
        if (val != temp.val) return val > temp.val;
        return id > temp.id;
    }
};
int main() {
    priority_queue q;
    char str[20];
    while (~scanf("%s", str) && str[0] != '#') {
        int a, b; scanf("%d %d", &a, &b);
        q.push(Date(b, a, b));
    }
    int k; scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
        Date ans = q.top(); q.pop();
        printf("%d\n", ans.id);
        ans.val += ans.add;
        q.push(ans);
    }
}


你可能感兴趣的:(数据结构)