P1382 楼房

每个矩形拆成2个坐标按$x$轴排序,蓝后$multiset$维护最高值。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
int n,h,H,tot;
pair<int,int> a[],f[];
multiset<int> s;
#define mp make_pair
#define fi first
#define se second
int main(){
scanf("%d",&n);
for(int i=,b,c,d;i<n;++i){
scanf("%d%d%d",&b,&c,&d);
a[i<<]=mp(c,b); a[i<<|]=mp(d,-b);//拆成2个坐标
}n<<=;sort(a,a+n);
s.insert();
for(int i = , j; i < n; i = j){
for(j=i;j < n;++j){
if(a[i].fi!=a[j].fi) break;
if(a[j].se>) s.insert(a[j].se);
else s.erase(s.find(-a[j].se));
}H=*s.rbegin();//s.rbegin():指向s的最后一个元素
if(h!=H){
f[++tot]=mp(a[i].fi,h);
f[++tot]=mp(a[i].fi,H);
h=H;
}
}printf("%d\n",tot);
for(int i=;i<=tot;++i)
printf("%d %d\n",f[i].fi,f[i].se);
return ;
}

P1382 楼房的更多相关文章

  1. luogu P1382 楼房

    二次联通门 : luogu P1382 楼房 /* luogu P1382 楼房 线段树 + 扫描线 + 离散化 正解貌似是堆... MMP...二段式线段树各种错误... 离散化一下横坐标 扫描线扫 ...

  2. P1382 楼房 set用法小结

    这个sb题目,剧毒... STL大法好 首先,我准备用经典的线段树优化扫描线来做.之前的矩形周长把我困了数天导致我胸有成竹. 然后,敲代码半小时,调试半个月......这个,sb,怎么改都是0分+2个 ...

  3. [洛谷P1382] 楼房

    题目描述 地平线(x轴)上有n个矩(lou)形(fang),用三个整数h[i],l[i],r[i]来表示第i个矩形:矩形左下角为(l[i],0),右上角为(r[i],h[i]).地平线高度为0.在轮廓 ...

  4. P1382 楼房 (扫描线,线段树)

    题目描述 地平线(x轴)上有n个矩(lou)形(fang),用三个整数h[i],l[i],r[i]来表示第i个矩形:矩形左下角为(l[i],0),右上角为(r[i],h[i]).地平线高度为0.在轮廓 ...

  5. 楼房 洛谷1382 && codevs2995

    P1382 楼房 题目描述 地平线(x轴)上有n个矩(lou)形(fang),用三个整数h[i],l[i],r[i]来表示第i个矩形:矩形左下角为(l[i],0),右上角为(r[i],h[i]).地平 ...

  6. AC日记——楼房 codevs 2995

    2995 楼房  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 地平线(x轴)上有n个矩(lou ...

  7. Bzoj2957 楼房重建

    Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1516  Solved: 723[Submit][Status][Discuss] Descripti ...

  8. 【清华集训】楼房重建 BZOJ 2957

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...

  9. 扫描线+堆 codevs 2995 楼房

    2995 楼房  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 地平线(x轴)上有n个矩(lou)形(fan ...

随机推荐

  1. shell 中 标准输出和错误输出

    命令 标准输出 标准错误 >/dev/null 2>&1 丢弃 丢弃 2>&1 >/dev/null 丢弃 屏幕 1>/dev/null 丢弃 屏幕 2& ...

  2. python 常见报错汇总

    python官方文档:https://docs.python.org/zh-cn/3/tutorial/index.html 1.indentationerror:unindent does not ...

  3. js模拟队列----小优先队列

    队列:先进先出,后进后出 var Queue = (function(){ var item = new WeakMap(); class Queue{ constructor(){ item.set ...

  4. 实践 : Ubuntu 上 Testlink 部署

    1.安装apache sudo apt-get install apache2 2. sudo /etc/init.d/apache2 restart 测试: Http:\localhost or I ...

  5. lambda 表达式拼接

    类库: using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions ...

  6. python class 1

    //test.py class Employee: 'all employee' empCount = 0 def __init__(self, name, salary): self.name = ...

  7. 5.C#释放非托管资源1

    释放非托管资源 在介绍释放非托管资源的时候,我觉得有必要先来认识一下啥叫非托管资源,既然有非托管资源,肯定有托管资源. 托管资源指的是.net可以自棕进行回收的资源,主要是指托管堆上分配的内存资源.托 ...

  8. 虚拟机 liunx系统以 root 身份登录权限

    开启虚拟机 打开终端开启root账户 :sudo passwd -u root 输入当前用户的密码   为root账户设置密码:sudo passwd root 设置root密码,输入两次   测试r ...

  9. tp5 auth权限设置

    案例:把所需要的auth类放在一个公共的地方引用,我这里就只是放在了与application同级的extend里面的org所以我在公共控制器里面实例为use \org\Auth; 然后我再公共控制器里 ...

  10. jQuery-图片轮播-随意切换图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...