BZOJ1216 [HNOI2003]操作系统(洛谷P2278)

该博客主要介绍了如何使用堆进行模拟操作,针对BZOJ1216和洛谷P2278题目,提出了采用双关键字堆的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

堆 模拟

BZOJ题目传送门
洛谷题目传送门

搞个双关键字堆瞎模拟就好了。

代码:

#include<queue>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define F inline
#define N 15005
using namespace std;
struct pro{ int id,s,t,x; }tmp;
priority_queue <pro> q;
int lst,t;
F char readc(){
    static char buf[100000],*l=buf,*r=buf;
    if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
    return l==r?EOF:*l++;
}
F int _read(){
    int x=0; char ch=readc();
    while (!isdigit(ch)&&ch!=EOF) ch=readc();
    if (ch==EOF) return -1;
    while (isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=readc();
    return x;
}
F bool read(pro &a){
    int id=_read(),s=_read(),t=_read(),x=_read();
    if (~id) return a=(pro){id,s,t,x},1; return 0;
}
F void writec(int x){ if (x>9) writec(x/10); putchar(x%10+48); }
F void _write(int x,bool f){ writec(x),putchar(f?' ':'\n'); }
F bool operator <(pro a,pro b){ return a.x==b.x?a.s>b.s:a.x<b.x; }
int main(){
    while (read(tmp)){
        t=tmp.s-lst;
        while (!q.empty()){
            pro tp=q.top(); q.pop();
            if (tp.t>t){ tp.t-=t,lst+=t,q.push(tp),t=0; break; }
            else t-=tp.t,lst+=tp.t,_write(tp.id,1),_write(lst,0);
        }
        lst+=t,q.push(tmp);
    }
    while (!q.empty())
        lst+=(tmp=q.top()).t,q.pop(),_write(tmp.id,1),_write(lst,0);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值