BZOJ 1216 操作系统(堆)

时间:2024-11-11 11:07:02

用堆模拟题目中的操作即可。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... struct node{
int id, to, t, now, level;
node(int _id=, int _to=, int _t=, int _level=):id(_id),to(_to),t(_t),level(_level){}
bool operator <(const node&r)const{
if (level!=r.level) return level<r.level;
return to>r.to;
}
};
priority_queue<node>que; int main ()
{
node tmp;
int id, to, t, level, f=;
while (~scanf("%d%d%d%d",&id,&to,&t,&level)) {
while (!que.empty()) {
tmp=que.top(); que.pop();
if (tmp.t<=to-f) f+=tmp.t, printf("%d %d\n",tmp.id,f);
else {tmp.t-=(to-f); que.push(tmp); break;}
}
f=to;
que.push(node(id,to,t,level));
}
while (!que.empty()) {
tmp=que.top(); que.pop();
f+=tmp.t;
printf("%d %d\n",tmp.id,f);
}
return ;
}