bzoj1216: [HNOI2003]操作系统

传送门
直接用堆模拟不虚。

var
  a,b,c,d:array [0..300005] of longint;
  n,h,t,time,i,j:longint;
procedure set1(x:longint);
  var
    t:longint;
  begin
    while (x>1) do
      if (d[x]>d[x div 2]) or ((d[x]=d[x div 2]) and (b[x]<d[x div 2]))then
        begin
          t:=d[x]; d[x]:=d[x div 2]; d[x div 2]:=t;
          t:=c[x]; c[x]:=c[x div 2]; c[x div 2]:=t;
          t:=b[x]; b[x]:=b[x div 2]; b[x div 2]:=t;
          t:=a[x]; a[x]:=a[x div 2]; a[x div 2]:=t;
          x:=x div 2;
        end
       else break;
  end;
procedure set2(x:longint);
  var
    s,t:longint;
  begin
    while (x*2<=h) do
      begin
        if (x*2+1>h) or ((d[x*2]>d[x*2+1]) or
          ((d[x*2]=d[x*2+1]) and (b[2*x]<b[2*x+1]))) then
            t:=x*2 else t:=x*2+1;
        if (d[t]>d[x]) or ((d[t]=d[x]) and (b[t]<b[x])) then
          begin
            s:=d[t]; d[t]:=d[x]; d[x]:=s;
            s:=c[t]; c[t]:=c[x]; c[x]:=s;
            s:=b[x]; b[x]:=b[t]; b[t]:=s;
            s:=a[x]; a[x]:=a[t]; a[t]:=s;
            x:=t;
          end
         else break;
      end;
  end;
begin
  n:=0;
  while not(eof) do
    begin      inc(n);
      readln(a[n],b[n],c[n],d[n]);
    end;
  a[n+1]:=10000000; b[n+1]:=1000000000;
  c[n+1]:=1; d[n+1]:=1;
  h:=1;
  t:=0;
  i:=2;
  time:=b[1];
  while (t<=n) and (i<=n) do
    begin
      while (time+c[1]<=b[i]) and (h>0) do
        begin
          time:=time+c[1];
          writeln(a[1],' ',time);
          a[1]:=a[h]; b[1]:=b[h]; c[1]:=c[h]; d[1]:=d[h];
          dec(h); set2(1); inc(t);
        end;
      if (h>0) then c[1]:=c[1]-(b[i]-time);
      time:=b[i]; inc(h);
      a[h]:=a[i]; b[h]:=b[i]; c[h]:=c[i]; d[h]:=d[i];
      set1(h); inc(i);
    end;
  for i:=t+1 to n do
    begin
      time:=time+c[1];
      writeln(a[1],' ',time);
      c[1]:=c[h]; a[1]:=a[h]; b[1]:=b[h]; d[1]:=d[h];
      dec(h); set2(1);
    end;
end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值