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 ...
随机推荐
- vue 点击切换图标
<div @click="showImg" class="showSearch"> <img class="header_img&q ...
- hdu 3746 kmp的next数组理解
题目大意: 求最少在结尾补上几个字符才能形成循环 基本思路: next数组有一个性质,长度为len的字符串的最小长度的循环节(可能没有,但有的话一定是)len-next[len],因为最长不能是原串, ...
- Java/sql找出oracle数据库有空格的列
1.java方式 String table_sql = "select table_name from user_tables";//所有用户表 List<String> ...
- OpenSearch最新功能介绍
摘要:阿里云开放搜索(OpenSearch)是一款结构化数据搜索托管服务,其能够提供简单.高效.稳定.低成本和可扩展的搜索解决方案.OpenSearch以平台服务化的形式,将专业搜索技术简单化.低门槛 ...
- 重新开始学习C++
从2002年,大二的那个夏天开始,就接触了C++这门语言,大学那会就是在老师不停教育下,背诵C++的各种特征,完全不知道C++干嘛用的,当然自然也是不知道汇编语言,C语言是干嘛用的,老师让学就学吧.那 ...
- linux IPC 消息队列
消息队列函数原型 在建立IPC通讯时(如消息队列,共享内存)必须建立一个ID值.通常情况下,这个ID值由ftok函数得到 #inlcude <sys/types.h> #include & ...
- 为delphi程序添加脚本功能,用脚本控制delphi程序
使用微软的ActiveX Scripting技术,可以在应用程序中集成使用vbscript或这javascript脚本语言.在delphi中点击Component菜单的Import Activex C ...
- Delphi 判断某个系统服务是否存在及相关状态
记得use WinSvc; //------------------------------------- // 获取某个系统服务的当前状态 // // return status code if s ...
- (转)OpenFire源码学习之二:Mina基础知识
转:http://blog.csdn.net/huwenfeng_2011/article/details/43413009 Mina概述 Apache MINA(Multipurpose Infra ...
- 百度API实例——google地图数据转化为百度地图数据
前段时间做的项目前端都是用Google地图,最近在一个地方需要用到百度地图,因为不同地图都有自己的处理,同一个经纬度在不同地图上显示的位置并不相同,因此,要把以前的数据直接拿过来用需要做一个转换.查阅 ...