bzoj1216: [HNOI2003]操作系统

堆。

一道模拟,不过不同的人模拟出来的效果差距很大,比方说我抄的这个就太劲了。。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
struct data {
    int n,s,t,p;
    data() {}
    data(int n,int s,int t,int p):n(n),s(s),t(t),p(p) {}
    
    bool operator < (const data& rhs) const {
        return p<rhs.p || (p==rhs.p && s>rhs.s);    
    }
};
priority_queue<data> q;
int n,s,t,p,d,T=0;
data x;

int main() {
    while(scanf("%d%d%d%d",&n,&s,&t,&p)!=EOF) {
        while(T<s&&!q.empty()) {
            x=q.top(); q.pop();
            d=min(x.t,s-T);
            T+=d;
            x.t-=d;
            if(x.t) q.push(x);
            else printf("%d %d
",x.n,T);
        }
        q.push(data(n,s,t,p));
        T=s;
    }
    while(!q.empty()) {
        x=q.top(); q.pop();
        printf("%d %d
",x.n,T+=x.t);    
    }
    return 0;
}
原文地址:https://www.cnblogs.com/invoid/p/5536430.html