1029: [JSOI2007]建筑抢修 - BZOJ
Description
小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者。但是T部落的基地里已经有N个建筑设施受到了严重的损伤,如果不尽快修复的话,这些建筑设施将会完全毁坏。现在的情况是:T部落基地里只有一个修理工人,虽然他能瞬间到达任何一个建筑,但是修复每个建筑都需要一定的时间。同时,修理工人修理完一个建筑才能修理下一个建筑,不能同时修理多个建筑。如果某个建筑在一段时间之内没有完全修理完毕,这个建筑就报废了。你的任务是帮小刚合理的制订一个修理顺序,以抢修尽可能多的建筑。
Input
第一行是一个整数N,接下来N行每行两个整数T1,T2描述一个建筑:修理这个建筑需要T1秒,如果在T2秒之内还没有修理完成,这个建筑就报废了。
Output
输出一个整数S,表示最多可以抢修S个建筑。 数据范围: N<150000,T1
Sample Input
4
100 200
200 1300
1000 1250
2000 3200
Sample Output
3
先对t2进行排序,然后一个个加入
如果now+t1<=t2,就直接加入
如果now+t1>t2,那么就用它和已经加入的时间最大的比较,如果t1比它小就替换它
用大根堆维护最大时间
const
maxn=; type
node=record
t1,t2:longint;
end; var
a:array[..maxn]of node;
n:longint; procedure swap(var x,y:node);
var
t:node;
begin
t:=x;x:=y;y:=t;
end; procedure sort(l,r:longint);
var
i,j,y:longint;
begin
i:=l;j:=r;
y:=a[(l+r)>>].t2;
repeat
while a[i].t2<y do
inc(i);
while a[j].t2>y do
dec(j);
if i<=j then
begin
swap(a[i],a[j]);
inc(i);
dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end; procedure init;
var
i:longint;
begin
read(n);
for i:= to n do
with a[i] do
read(t1,t2);
sort(,n);
end; var
q:array[..maxn]of node;
now,tot:longint; procedure down(x:longint);
var
i:longint;
begin
i:=x<<;
while i<=tot do
begin
if (i<tot) and (q[i+].t1>q[i].t1) then inc(i);
if q[x].t1<q[i].t1 then
begin
swap(q[x],q[i]);
x:=i;
i:=x<<;
end
else break;
end;
end; procedure up(x:longint);
var
i:longint;
begin
while x> do
begin
i:=x>>;
if q[x].t1>q[i].t1 then
begin
swap(q[i],q[x]);
x:=i;
i:=x>>;
end
else break;
end;
end; procedure work;
var
i:longint;
begin
for i:= to n do
if now+a[i].t1<=a[i].t2 then
begin
inc(tot);
q[tot]:=a[i];
up(tot);
inc(now,a[i].t1);
end
else
if a[i].t1<q[].t1 then
begin
now:=now-q[].t1+a[i].t1;
swap(a[i],q[]);
down();
end;
write(tot);
end; begin
init;
work;
end.
1029: [JSOI2007]建筑抢修 - BZOJ的更多相关文章
- BZOJ 1029: [JSOI2007]建筑抢修 堆+贪心
1029: [JSOI2007]建筑抢修 Description 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有 ...
- BZOJ 1029 [JSOI2007] 建筑抢修(贪心)
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 2285 Solved: 1004[Submit][Statu ...
- BZOJ 1029 [JSOI2007]建筑抢修 已更新
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 2748 Solved: 1213[Submit][Statu ...
- BZOJ 1029: [JSOI2007]建筑抢修
1029: [JSOI2007]建筑抢修 Description 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有 ...
- BZOJ 1029: [JSOI2007]建筑抢修【优先队列+贪心策略】
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 4810 Solved: 2160[Submit][Statu ...
- BZOJ 1029 [JSOI2007]建筑抢修 (贪心 + 优先队列)
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 5452 Solved: 2422[Submit][Statu ...
- BZOJ 1029: [JSOI2007]建筑抢修 优先队列
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- 1029: [JSOI2007]建筑抢修
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 2382 Solved: 1033[Submit][Statu ...
- BZOJ 1029: [JSOI2007]建筑抢修 贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1029 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落 ...
随机推荐
- C# WPF 连接数据库Sqlhelper类
从视频上学习到的WPF连接数据库的方法 需要配置一个 configuration 文件,包含 SQL instance 的相关信息 using System; using System.Collect ...
- 关于Class.forName("oracle.jdbc.driver.OracleDriver");报ClassNotFoundException 的异常
关于try { Class.forName("oracle.jdbc.driver.OracleDriver"); }catch(ClassNotFoundException e) ...
- CSS之显示天气
这个可以有,自从有了这个,以后查询天气就方便多了,哈哈. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...
- 随笔之Android平台上的进程调度探讨
http://blog.csdn.net/innost/article/details/6940136 随笔之Android平台上的进程调度探讨 一由来 最近在翻阅MediaProvider的时候,突 ...
- Linux命令(5):cp命令
1.作用: 将给出的文件或目录复制到另一文件或目录中: 2.格式: cp [选项] 源文件或目录 目标文件或目录. 3.常见参数: 4.使用实例: [root@localhost ~]# cp -a ...
- apktool反编译工具
几个报错的解决办法 apktool反编译时经常会出现下面的信息 Input file was not found or was not readable. Destination directory ...
- ZipArchive 的使用
新建一个项目,首先添加 System.IO.Compression.FileSystem 引用. 解压文件 using System.IO.Compression; namespace cl { st ...
- spring quartz 定时任务“Failed to load class "org.slf4j.impl.StaticLoggerBinder”“Checking for available updated version of Quartz”
Failed to load class "org.slf4j.impl.StaticLoggerBinder 需要slf4j-api.jar.slf4j-log4j12.jar Check ...
- C++ 的隱式型別轉換
先上一段代碼, 這段代碼竟然可以編譯過,我的老天! class Boo { Boo(int c){ cout << "I'm Boo"; } }; void do_so ...
- 用一天的时间学习Java EE中的SSH框架
首先说明一下,本人目前主要从事.NET领域的工作,但对于C++.Java.OC等语言也略知一二,周末闲来无事,特花费一天的时间学习了一下Java中的SSH框架,希望把学习过程中的心得体会与园友们进行分 ...