1029: [JSOI2007]建筑抢修
题目:
http://www.lydsy.com/JudgeOnline/problem.php?id=1029
用大根堆维护的简单贪心。
先按t2从小到大排序。
按顺序处理:如果当前时间加上t1<=t2,那么t1入堆,答案加一;
否则,如果堆顶元素比t1大,用t1把堆顶元素替换掉。
#include
<
iostream
>
#include
<
cstdio
>
#include
<
queue
>
#include
<
algorithm
>
using
namespace
std;
const
int
MaxN
=
150050
;
struct
building
{
int
t1,t2;
}
;
int
n,now
=
0
,ans
=
0
;
building a[MaxN];
priority_queue
<
int
>
q;
bool
cmp(building a,building b)
{
return
a.t2
<
b.t2;
}
int
main()
{
cin
>>
n;
for
(
int
i
=
0
;i
<
n;i
++
)
{
cin
>>
a[i].t1
>>
a[i].t2;
}
sort(a,a
+
n,cmp);
for
(
int
i
=
0
;i
<
n;i
++
)
{
if
(now
+
a[i].t1
<=
a[i].t2)
{
q.push(a[i].t1);
now
+=
a[i].t1;
ans
++
;
}
else
{
int
top
=
q.top();
if
(top
>
a[i].t1)
{
now
=
now
-
top
+
a[i].t1;
q.pop();
q.push(a[i].t1);
}
}
}
cout
<<
ans
<<
endl;
return
0
;
}
posted on 2013-02-13 21:55
Kiro
阅读(170)
评论(0)
编辑
收藏
引用
所属分类:
衡八oj
只有注册用户
登录
后才能发表评论。
相关文章:
1055: [HAOI2008]玩具取名
1054: [HAOI2008]移动玩具
1051: [HAOI2006]受欢迎的牛
1050: [HAOI2006]旅行comf
1046: [HAOI2007]上升序列
1042: [HAOI2008]硬币购物
1037: [ZJOI2008]生日聚会Party
1034: [ZJOI2008]泡泡堂BNB
1029: [JSOI2007]建筑抢修
1027: [JSOI2007]合金
网站导航:
博客园
博客园最新博文
博问
管理
4myOI
再给我一次机会将故事改写。
导航
C++博客
首页
新随笔
联系
聚合
管理
统计
随笔 - 0
文章 - 27
评论 - 0
引用 - 0
常用链接
我的随笔
我的评论
我参与的随笔
留言簿
给我留言
查看公开留言
查看私人留言
文章分类
■
hdu(1)
(rss)
■
poj(2)
(rss)
■
衡八oj(24)
(rss)
■
其他
(rss)
文章档案
■
2013年2月 (17)
■
2013年1月 (3)
■
2012年10月 (3)
■
2012年9月 (1)
■
2012年3月 (1)
■
2012年2月 (2)
搜索
最新评论