UVALive 3135

题意很简单就不说了,见白书指导书P188
这里就是学习一下priority的最简单的用法,自己写一个结构体,包含比较操作 operator <, 然后就ok了

代码

#include <stdio.h>
#include <iostream>
#include <queue>
using namespace std;
structzz{
	int n, p, t;
	bool operator < (const zz&z) const{
		return t > z.t || (t==z.t && n>z.n);
	}
};
int main(){
	priority_queue<zz>pq;
	char s[20];
	zzz;
	while(scanf("%s", s) && s[0]!='#'){
		scanf("%d%d", &z.n, &z.p);
		z.t = z.p;
		pq.push(z);
	}
	int k;
	scanf("%d", &k);
	while(k--){
		zztz = pq.top();
		printf("%d\n", tz.n);
		tz.t += tz.p;
		pq.pop();
		pq.push(tz);
	}
}
原文地址:https://www.cnblogs.com/zjutzz/p/3207872.html