其他分享
首页 > 其他分享> > 做题记录 Luogu P2278

做题记录 Luogu P2278

作者:互联网

Luogu P2278 [HNOI2003]操作系统

A few moments later...

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1000005
struct node
{
	ll num, arr, tim, pri;
};
node a[N];
bool operator < (node a1, node a2)
{
	if(a1.pri != a2.pri)
	{
		return a1.pri < a2.pri;
	}
	return a1.num > a2.num;
}
priority_queue<node> q;
ll tot = 0, Time = 0;
int main()
{
	while(tot++, scanf("%lld%lld%lld%lld", &a[tot].num, &a[tot].arr, &a[tot].tim, &a[tot].pri) != EOF)
	{
		while(!q.empty() && Time + q.top().tim <= a[tot].arr)
		{
			Time += q.top().tim;
			printf("%lld %lld\n", q.top().num, Time);
			q.pop();
		}
		if(!q.empty())
		{
			node u = q.top();
			q.pop();
			u.tim = u.tim - a[tot].arr + Time;
			q.push(u);
		}
		q.push(a[tot]);
		Time = a[tot].arr;
	}
	while(!q.empty())
	{
		printf("%lld %lld\n", q.top().num, Time + q.top().tim);
		Time += q.top().tim;
		q.pop();
	}
	return 0;
}

标签:node,记录,Luogu,pri,tot,a1,num,P2278,a2
来源: https://www.cnblogs.com/fanypcd/p/14957061.html