bzoj 1216: [HNOI2003]操作系統

題目鏈接


【想說的話】

聽說03年不讓用stl...

所以就會產生這樣的題...


【題解】

用優先隊列按照題意模擬就好了


【代碼】

#include<bits/stdc++.h>

using namespace std;

struct node{
	int num,ti,t,x;
	friend bool operator < (node a,node b){
		if(a.x==b.x)return a.ti>b.ti;
		return a.x<b.x;
	}
};

int a,b,c,d,T=0;
priority_queue<node>q;

int main(){
	while(~scanf("%d%d%d%d",&a,&b,&c,&d)){
		while(!q.empty() && T<b){
			node tmp=q.top();
			q.pop();
			T=max(T,tmp.ti);
			int s=min(b-T,tmp.t);
			T+=s;
			tmp.t-=s;
			if(tmp.t)q.push(tmp);
			else printf("%d %d\n",tmp.num,T);
		}
		q.push((node){a,b,c,d});
	}
	while(!q.empty()){
		node tmp=q.top();
		q.pop();
		printf("%d %d\n",tmp.num,T+=tmp.t);
	}
	
	return 0;
}


發佈了128 篇原創文章 · 獲贊 72 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章