[USACO2007OPENS] City Horizon S
题目描述
Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings.
The entire horizon is represented by a number line with N (1 ≤ N ≤ 40,000) buildings. Building i's silhouette has a base that spans locations Ai through Bi along the horizon (1 ≤ Ai < Bi ≤ 1,000,000,000) and has height Hi (1 ≤ Hi ≤ 1,000,000,000). Determine the area, in square units, of the aggregate silhouette formed by all N buildings.
输入格式
第一行一个整数N,然后有N行,每行三个正整数ai、bi、Hi。
输出格式
一个数,数列中所有元素的和。
样例 #1
样例输入 #1
4
2 5 1
9 10 4
6 8 2
4 6 3
样例输出 #1
16
提示
\(N<=40000 , a、b、k<=10^9\) 。
所有的左端点和右端点把线段切成了很多段,每一段的值都是一样的。
把所有左右端点离散一下,然后从左到右枚举每一段。那么就要研究这个时候每一段的值是什么。
可以开一个set维护现在有的高度,这一段的高度就是现有的高度的最大值。我们遇到一个左端点就把对应高度放入set,遇到一个右端点就把对应高度从set中删去。然后一段的面积和就是长度*最大值。加起来即可
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
int a,b,h;
int n;
long long ans;
multiset<int>s;
struct evt{
int x,h;
bool operator<(const evt e)const{
return x<e.x;
}
}e[80005];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a>>b>>h;
e[2*i-1]=(evt){a,h};
e[2*i]=(evt){b,-h};
}
sort(e+1,e+2*n+1);
s.insert(0);
for(int i=1;i<=2*n;i++)
{
if (i!=1&&!s.empty()) ans += (long long)(e[i].x-e[i - 1].x)*(*s.rbegin());
if(e[i].h>0)
s.insert(e[i].h);
else
s.erase(s.find(-e[i].h));
}
cout<<ans<<endl;
}
[USACO2007OPENS] City Horizon S的更多相关文章
- [POJ3277]City Horizon
[POJ3277]City Horizon 试题描述 Farmer John has taken his cows on a trip to the city! As the sun sets, th ...
- 离散化+线段树 POJ 3277 City Horizon
POJ 3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18466 Accepted: 507 ...
- poj City Horizon (线段树+二分离散)
http://poj.org/problem?id=3277 City Horizon Time Limit: 2000MS Memory Limit: 65536K Total Submissi ...
- 1645: [Usaco2007 Open]City Horizon 城市地平线
1645: [Usaco2007 Open]City Horizon 城市地平线 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 315 Solved: ...
- bzoj1645 [Usaco2007 Open]City Horizon 城市地平线
Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at ...
- BZOJ_1654_[Usaco2007 Open]City Horizon 城市地平线_扫描线
BZOJ_1654_[Usaco2007 Open]City Horizon 城市地平线_扫描线 Description N个矩形块,交求面积并. Input * Line 1: A single i ...
- bzoj1645 / P2061 [USACO07OPEN]城市的地平线City Horizon(扫描线)
P2061 [USACO07OPEN]城市的地平线City Horizon 扫描线 扫描线简化版 流程(本题为例): 把一个矩形用两条线段(底端点的坐标,向上长度,添加$or$删除)表示,按横坐标排序 ...
- 【BZOJ1645】[Usaco2007 Open]City Horizon 城市地平线 离散化+线段树
[BZOJ1645][Usaco2007 Open]City Horizon 城市地平线 Description Farmer John has taken his cows on a trip to ...
- 【BZOJ】1645: [Usaco2007 Open]City Horizon 城市地平线(线段树+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1645 这题的方法很奇妙啊...一开始我打了一个“离散”后的线段树.............果然爆了. ...
- xtu数据结构 H. City Horizon
H. City Horizon Time Limit: 2000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java cl ...
随机推荐
- 【pytorch】目标检测:YOLO的基本原理与YOLO系列的网络结构
利用深度学习进行目标检测的算法可分为两类:two-stage和one-stage.two-stage类的算法,是基于Region Proposal的,它包括R-CNN,Fast R-CNN, Fast ...
- 论文解读(TAMEPT)《A Two-Stage Framework with Self-Supervised Distillation For Cross-Domain Text Classification》
论文信息 论文标题:A Two-Stage Framework with Self-Supervised Distillation For Cross-Domain Text Classificati ...
- Abp vNext 模块加载机制
文章目录 生命周期 PreConfigureServices 添加依赖注入或者其它配置之前 ConfigureServices 添加依赖注入或者其它配置 PostConfigureServices 添 ...
- Rockchip rk3588 U-Boot详解 (三)
Rockchip rk3588 U-Boot详解 (三) 专栏总目录 1.1 Environment-Variables ENV(Environment-Variables)是U-Boot支持的一种全 ...
- Pandas 读取 Excel 斜着读
读取 Excel 斜着读数据 import pandas as pd def read_sideling(direction, sheet_name, row_start, col_start, ga ...
- 使用Github Action实现构建、发布到 nuget.org
使用Github Action实现构建.发布到 nuget.org GitHub Actions是GitHub提供的持续集成和持续部署(CI/CD)工具,它能够自动化构建.测试和部署你的项目.在这篇教 ...
- Arrays.asList()把数组转换成集合时,不能使用其修改集合相关的方法
Arrays.asList()把数组转换成集合时,不能使用其修改集合相关的方法,此处测试代码如下,这里使用add方法: 1 public class main { 2 public static vo ...
- LocalDateTime、LocalDate、Date、String相互转化大全及其注意事项
一.前言 大家在开发过程中必不可少的和日期打交道,对接别的系统时,时间日期格式不一致,每次都要转化! 每次写完就忘记了,小编专门来整理一篇来详细说一下他们四个的转换的方法,方便后面使用!! 二.Loc ...
- k8s部署xxl-job-admin
概述 XXL-JOB是一个轻量级分布式任务调度平台,其核心设计目标是开发迅速.学习简单.轻量级.易扩展.现已开放源代码并接入多家公司线上产品线,开箱即用. 下载好要用到的镜像 docker pull ...
- TS实现汉诺塔算法,以及图灵完备讨论
之前在网上看到徐大佬更新的一篇文章: 用 TypeScript 类型运算实现一个中国象棋程序 在线预览地址:https://tsplay.dev/Nd4n0N 把鼠标放在最后几行的走棋结果上,惊喜的一 ...