【题解】LuoGu2278:[HNOI2003]操作系统

原题传送门
用堆模拟操作系统即可

Code:

#include 
#define maxn 1000010
using namespace std;
struct heap{
	int id, st, t, level;
	bool operator < (const heap &x) const { return x.level == level ? x.st < st : x.level > level; }
};
priority_queue <heap> q;
int id[maxn], st[maxn], t[maxn], level[maxn], n;

int main(){
	freopen("1.txt", "r", stdin);
	while (~scanf("%d%d%d%d", &id[n + 1], &st[n + 1], &t[n + 1], &level[n + 1])) ++n;
	st[n + 1] = 2e9;
	for (int i = 1; i <= n; ++i){
		q.push((heap){id[i], st[i], t[i], level[i]});
		int s = st[i];
		while (!q.empty()){
			heap tmp = q.top(); q.pop();
			if (tmp.t <= st[i + 1] - s) s += tmp.t, printf("%d %d\n", tmp.id, s);
			else{ tmp.t -= (st[i + 1] - s); q.push(tmp); break; }
		}
	}
	return 0;
}

你可能感兴趣的:(题解,LuoGu,优先队列(堆),题解,LuoGu,堆)