[BZOJ 1029][JSOI2007]建筑抢修
来源:互联网 发布:会计电算化软件下载 编辑:程序博客网 时间:2024/05/01 09:09
[JSOI2007]建筑抢修
Time Limit: 4 Sec Memory Limit: 162 MB
Description
小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者。但是T部落的基地里已经有N个建筑设施受到了严重的损伤,如果不尽快修复的话,这些建筑设施将会完全毁坏。现在的情况是:T部落基地里只有一个修理工人,虽然他能瞬间到达任何一个建筑,但是修复每个建筑都需要一定的时间。同时,修理工人修理完一个建筑才能修理下一个建筑,不能同时修理多个建筑。如果某个建筑在一段时间之内没有完全修理完毕,这个建筑就报废了。你的任务是帮小刚合理的制订一个修理顺序,以抢修尽可能多的建筑。
Input
第一行是一个整数N,接下来N行每行两个整数T1,T2描述一个建筑:修理这个建筑需要T1秒,如果在T2秒之内还没有修理完成,这个建筑就报废了。
Output
输出一个整数S,表示最多可以抢修S个建筑.N < 150,000; T1 < T2 < maxlongint
Sample Input
4
100 200
200 1300
1000 1250
2000 3200
Sample Output
3
题解
- 贪心,用大根堆来维护最大值
- 先对结束时间排序
- 每次选取的任务能完成则完成
- 完不成的与对顶元素比较,如果比堆顶小且不执行对顶而执行当前任务可完成,则弹出堆顶,将该任务压入堆中
var y:array[0..150000]of longint; x:array[0..150000,1..2]of longint; i,j,k:longint; n,t:longint;procedure sort(l,r: longint);var i,j,a,y: longint;begin i:=l; j:=r; a:=x[(l+r) div 2,2]; repeat while x[i,2]<a do inc(i); while a<x[j,2] do dec(j); if not(i>j) then begin y:=x[i,1]; x[i,1]:=x[j,1]; x[j,1]:=y; y:=x[i,2]; x[i,2]:=x[j,2]; x[j,2]:=y; inc(i); dec(j); end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r);end;procedure init(z:longint);var tt,a,b,c,s:longint;begin inc(y[0]); y[y[0]]:=z; tt:=y[0]; while tt>1 do begin if tt mod 2=1 then begin a:=tt-1; b:=tt; c:=a div 2; end else begin a:=tt; b:=a+1; c:=a div 2; end; if y[a]>y[c] then begin s:=y[a]; y[a]:=y[c]; y[c]:=s; end; if y[b]>y[c] then begin s:=y[b]; y[b]:=y[c]; y[c]:=s; end; tt:=c; end;end;procedure delet;var i,s:longint;begin for i:=1 to y[0]-1 do begin s:=y[i]; y[i]:=y[i+1]; y[i+1]:=s; end; dec(y[0]);end;begin readln(n); for i:=1 to n do readln(x[i,1],x[i,2]); sort(1,n); {for i:=1 to n do write(x[i,2],' '); writeln;} t:=0; for i:=1 to n do begin if t+x[i,1]<=x[i,2] then begin inc(t,x[i,1]); init(x[i,1]); end else if (t+x[i,1]-y[1]<=x[i,2])and(x[i,1]<y[1]) then begin inc(t,x[i,1]-y[1]); delet; init(x[i,1]); end; end; writeln(y[0]);end.
0 0
- BZOJ 1029: [JSOI2007]建筑抢修
- BZOJ 1029: [JSOI2007]建筑抢修
- bzoj 1029: [JSOI2007]建筑抢修
- 【BZOJ 1029】 [JSOI2007]建筑抢修
- [BZOJ 1029][JSOI2007]建筑抢修
- BZOJ 1029 [JSOI2007]建筑抢修
- 【bzoj 1029】 [JSOI2007]建筑抢修
- 【BZOJ 1029】[JSOI2007]建筑抢修
- [bzoj] 1029 [JSOI2007]建筑抢修
- BZOJ 1029: [JSOI2007]建筑抢修
- bzoj[JSOI2007]建筑抢修
- bzoj 1029 [JSOI2007] 建筑抢修 题解
- BZOJ 1029 JSOI2007 建筑抢修 贪心+堆
- 【BZOJ】1029 [JSOI2007]建筑抢修 贪心+堆
- bzoj 1029: [JSOI2007]建筑抢修 贪心+堆
- BZOJ 1029: [JSOI2007]建筑抢修 优先队列
- 1029: [JSOI2007]建筑抢修
- 1029: [JSOI2007]建筑抢修
- Jmeter 运行脚本 提示无法登录
- hadoop单个数据节点的不同存储路径的存储策略源码分析
- [断点调试好助手]LLDB调试
- Dart Essentials(读书笔记)——这本书很大篇幅都在谈AngularDart,Zones概念没谈到
- Spring学习笔记——Sprin管理Bean的原理
- [BZOJ 1029][JSOI2007]建筑抢修
- 最大子列和算法
- sql left join的多表应用
- nginx配置文件详解
- Spark开发问题集锦
- grep命令的详细使用方法
- 网站怎么运转的
- 约瑟夫环问题
- 怎样教四岁的孩子学画画