bzoj1029题解
【解题思路】
贪心,先按结束时间排序,从左到右扫描过去,如果当前建筑可以修复则入大根堆,否则,若其修复时间比堆顶小则弹出堆顶并入堆,处理完堆后则更新总时间。复杂度O(nlog2n)。
【参考代码】
#pragma GCC optimize(2)
#include <algorithm>
#include <cstdio>
#include <functional>
#include <set>
#define REP(i,low,high) for(register int i=(low);i<=(high);i++)
using namespace std;
struct node
{
int ft,et;
node() {}
int input() {return scanf("%d%d",&ft,&et);}
bool operator<(const node &another)const{return et<another.et;}
}a[];
int n;
multiset<int, greater<int> > sav;
int main()
{
scanf("%d",&n),sav.clear(); REP(i,,n) a[i].input(); sort(a+,a+n+);
int ans=,now=;
REP(i,,n)
{
if(a[i].ft+now<=a[i].et) sav.insert(a[i].ft),ans++,now+=a[i].ft;
else
{
multiset<int>::iterator tp=sav.begin();
if(*tp>a[i].ft) now+=a[i].ft-*tp,sav.erase(tp),sav.insert(a[i].ft);
}
}
return printf("%d\n",ans),;
}
bzoj1029题解的更多相关文章
- BZOJ1029: [JSOI2007]建筑抢修(贪心)
题目链接:BZOJ1029: [JSOI2007]建筑抢修 题解:贪心思想,按结束时间从小到大排序,选花费时间尽量短的建筑维修,用堆维护. #include<stdio.h> #inclu ...
- 【BZOJ1029】建筑抢修(贪心)
[BZOJ1029]建筑抢修(贪心) 题面 BZOJ 洛谷 题解 感觉自己已经不会贪心了. 很明显的一个想法是按照终止时间排序,然后能选则选. 但是这样子可能会因为前面选择了一个修理时间很长的,导致现 ...
- 【bzoj1029】【JSOI2007】建筑抢修
1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec Memory Limit: 162 MBSubmit: 6417 Solved: 2883[Submit][Statu ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
随机推荐
- hightchart 报错 Error in mounted hook: "Error: Highcharts error #17: www.highcharts.com/errors/17"
这个错误是应该导入hightchart 使用的相关的 东西 ,这里是worldcloud import Wordcloud from 'highcharts/modules/wordclou ...
- js 加载验证码
<img id="captchaPic" src="{{captcha_src('math')}}" onclick="this.src='{{ ...
- Magento笔记/记录(1)
1.Magento eav_attribute表中source如何指定自定义数据来源 如果你引用的类名为yebihai_usermanage_model_entity_school你必须完整的给出地 ...
- git——修改已经提交并push后的commit注释
把代码push到远程后,发现commit的注释居然多了几个错别字,不行,必须改了! 搜索了一些答案之后自己做了一个总结如下: ①修改倒数第次的commit 指令:$ git rebase -i HEA ...
- 搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程
http://blog.chinaunix.net/uid-20639775-id-154497.html
- renren-fast-vue-动态路由-添加路由-方式一(直接在原有结构上添加)
在原有文件夹夹下新建自己的组件 在 mock/modules/sys-menu.js 中引入 实现路由的添加
- 详解Windows注册表分析取证
大多数都知道windows系统中有个叫注册表的东西,但却很少有人会去深入的了解它的作用以及如何对它进行操作.然而对于计算机取证人员来说注册表无疑是块巨大的宝藏.通过注册表取证人员能分析出系统发生了什么 ...
- 2.5 webpack 进阶
配置分离 code splitting 异步加载 理解 webpack chunk webpack 调试 2.5.1 配置分离 在大型项目中,可能 webpack.config.js 会变得越来越臃肿 ...
- PAT_A1059#Prime Factors
Source: PAT A1059 Prime Factors (25 分) Description: Given any positive integer N, you are supposed t ...
- REST Client实际应用记录
请求Content-Type为application/x-www-form-urlencoded 先来看一个完整示例: ############## ### qa问答 @msg="糖尿病患者 ...