【解题思路】

  贪心,先按结束时间排序,从左到右扫描过去,如果当前建筑可以修复则入大根堆,否则,若其修复时间比堆顶小则弹出堆顶并入堆,处理完堆后则更新总时间。复杂度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题解的更多相关文章

  1. BZOJ1029: [JSOI2007]建筑抢修(贪心)

    题目链接:BZOJ1029: [JSOI2007]建筑抢修 题解:贪心思想,按结束时间从小到大排序,选花费时间尽量短的建筑维修,用堆维护. #include<stdio.h> #inclu ...

  2. 【BZOJ1029】建筑抢修(贪心)

    [BZOJ1029]建筑抢修(贪心) 题面 BZOJ 洛谷 题解 感觉自己已经不会贪心了. 很明显的一个想法是按照终止时间排序,然后能选则选. 但是这样子可能会因为前面选择了一个修理时间很长的,导致现 ...

  3. 【bzoj1029】【JSOI2007】建筑抢修

    1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec  Memory Limit: 162 MBSubmit: 6417  Solved: 2883[Submit][Statu ...

  4. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  5. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  6. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  7. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  8. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  9. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

随机推荐

  1. PHP创建多级目录文件夹

    PHP创建多级目录的代码实例如下: <?php function create_dir($dirName) { // 去除输入目录名中的空格部分 $dirName = trim($dirName ...

  2. leetcode-164周赛-1269-停在原地的方案数

    题目描述: 自己的提交: class Solution: def numWays(self, steps: int, arrLen: int) -> int: l = min(steps,arr ...

  3. web自动化框架抽取示例【Java+selenium】

    web自动化测试框架抽取示例 例子:测试登录模块,对登录的账号和密码进行不同的case校验. 1.1.1 无优化代码login_1 package com.lee.auto.testFrome; im ...

  4. 出现Warning: date(): It is not safe to rely on the system's timezone settings的解决办法

    在没有配置,尤其是新安装的PHP中使用date函数时,会报这个错误: Warning: date(): It is not safe to rely on the system's timezone ...

  5. CSS:CSS 导航栏

    ylbtech-CSS:CSS 导航栏 1.返回顶部 1. CSS 导航栏 导航栏 熟练使用导航栏,对于任何网站都非常重要. 使用CSS你可以转换成好看的导航栏而不是枯燥的HTML菜单. 导航栏=链接 ...

  6. JAR API

    JAR API包括使用 manifest 文件的类.Manifest类的一个对象表示一个manifest文件. 在代码中创建一个Manifest对象,如下所示: 1 Manifest manifest ...

  7. css3继承

    不可继承的:display.margin.border.padding.background.height.min-height.max- height.width.min-width.max-wid ...

  8. mysql高效导入导出load data [infile][outfile]用法

    一.MySQL高效导入数据的方法load data infile load data infile语句从一个文本文件中以很高的速度读入一个表中.使用这个命令之前,mysqld进程(服务)必须已经在运行 ...

  9. 我只会用threading,我菜

    #服务端 import socket import threading # import multiprocessing server=socket.socket(socket.AF_INET,soc ...

  10. Jmeter+ant

    1.下载 ant,解压到非中文目录,并配置环境变量,不会的自行 google 2.将 jmeter 中 extras 子目录里的 ant-jmeter-1.1.1.jar 复制到 ant 中的 lib ...