传送门

题目大意

给出一些墙,水从高往低流,每次只能到达一面墙,选择一个路径,使得路径上的流量的最小值最大。

分析

这是一道经典的扫描线题,我们发现能够合法的线段对数至多只有n对。将一条线段拆成两个点,自左向右排序依次加入set中,按照高度关系将它们相连,详见代码(也可以用线段树做这道题,有时间再补吧qwq)。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define sp cout<<"---------------------------------------------------"<<endl
const int inf=2e9+;
struct node {
int h,x,wh,id;
};
bool operator < (node a,node b){
if(a.x!=b.x)return a.x<b.x;
if(a.wh!=b.wh)return a.wh<b.wh;
return a.id<b.id;
}
vector<node>ev;
set<pair<int,int> >s;
vector<int>g[];
vector<int>c[];
int ans[],le[],ri[];
inline int what(int x,int y){return (min(ri[x],ri[y])-max(le[x],le[y]));}
inline int work(int x){
if(ans[x]!=-)return ans[x];
if(x==)return inf;
int res=;
for(int i=;i<(int)g[x].size();i++)
res=max(res,min(c[x][i],work(g[x][i])));
return ans[x]=res;
}
int main(){
int n,m,i,H,L,R;
scanf("%d%d",&n,&m);
n+=;
le[]=le[]=-inf;
ri[]=ri[]=inf;
for(i=;i<n;i++){
scanf("%d%d%d",&H,&L,&R);
le[i]=L;
ri[i]=R;
ev.push_back(node{H,L,,i});
ev.push_back(node{H,R,,i});
}
sort(ev.begin(),ev.end());
s.insert(make_pair(m,));
s.insert(make_pair(,));
for(i=;i<(int)ev.size();i++){
if(ev[i].wh==){
s.erase(make_pair(ev[i].h,ev[i].id));
}else {
set<pair<int,int> >::iterator it=
s.insert(make_pair(ev[i].h,ev[i].id)).first;
int dw=(--it)->second;
it++;
int up=(++it)->second;
if(g[up].size()&&g[up].back()==dw){
g[up].pop_back();
c[up].pop_back();
}
g[up].push_back(ev[i].id);
c[up].push_back(what(ev[i].id,up));
g[ev[i].id].push_back(dw);
c[ev[i].id].push_back(what(ev[i].id,dw));
}
}
memset(ans,-,sizeof(ans));
cout<<work()<<endl;
return ;
}

269D Maximum Waterfall的更多相关文章

  1. POJ3693 Maximum repetition substring [后缀数组 ST表]

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Acc ...

  2. Uncaught RangeError: Maximum call stack size exceeded 调试日记

    异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html 开发道路上不是解决问题最重要,而是解决问题的过程,这个过程我们称之为~~~调试 记 ...

  3. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  4. MTU(Maximum transmission unit) 最大传输单元

    最大传输单元(Maximum transmission unit),以太网MTU为1500. 不同网络MTU如下: 如果最大报文数据大小(MSS)超过MTU,则会引起分片操作.   路径MTU: 网路 ...

  5. uva 11059 maximum product(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  6. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  7. [LeetCode] Third Maximum Number 第三大的数

    Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...

  8. [LeetCode] Maximum Size Subarray Sum Equals k 最大子数组之和为k

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  9. [LeetCode] Create Maximum Number 创建最大数

    Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...

随机推荐

  1. ServlertContext

    1.ServletContext代表着整个JavaWeb应用,每个项目只有唯一的ServletContext的实例. 2.生命周期 服务器启动时创建 服务器关闭时销毁 3.获取ServletConte ...

  2. BEC listen and translation exercise 6

    能听懂自己的录音,说明发音还行,可惜听不懂... Another problem is that the members of the Biramichi fishing cooperative ar ...

  3. 重构代码 —— 函数即变量(Replace temp with Query)

    函数即变量,这里的函数指的是返回值为某一对象的函数.Replace temp with query,query 是一种查询函数. example 1 double price() { return t ...

  4. Technocup 2019 C. Compress String

    一个字符串 $s$,你要把它分成若干段,有两种合法的段 1.段长为 $1$,代价为 $a$ 2.这个段是前面所有段拼起来组成的字符串的字串,代价为 $b$ 问最小代价 $|s| \leq 5000$ ...

  5. LeetCode 323. Number of Connected Components in an Undirected Graph

    原题链接在这里:https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/ 题目: Giv ...

  6. hadoop完全分布式文件系统集群搭建

    一.准备工作: 1.找3台以上的主机(因为HDFS文件系统中保存的文件的blocak在datanode中至少要有3份或3份以上的备份,备份不能放于同一个机架上,更不能放于同一台主机上),我这里使用的是 ...

  7. spark远程调试

    基本流程1.远程运行spark,打开Spark master机器的JVM的jdwp,让其阻塞监听指定端口(8888),让其有终端向指定端口发送特定请求再执行:2.IntelliJ配置socket远程连 ...

  8. ECMAScript6入门-序言

    本系列笔记基于阮一峰大佬的开源书籍.如果大家想看可以去该地址 本系列笔记只记录本人自己学习的过程,如果有侵权收到通知会自行下架. 如果大家看到可以直接去地址处学习,如果觉得好还望支持正版. 在此感谢阮 ...

  9. (转)红帽 Red Hat Linux相关产品iso镜像下载【百度云】【更新6.7 Boot Disk】

    不为什么,就为了方便搜索,特把红帽EL 5.EL6 的各版本整理一下,共享出来. RedHat Enterprise Server 6.7 for i386 Boot Disk:rhel-server ...

  10. 基于OpenCV的火焰检测(二)——RGB颜色判据

    上文跟大家分享了在做火焰检测中常用到的图像预处理方法,从这一篇博文开始,我将向大家介绍如何一步一步地检测出火焰区域.火焰提取要用 到很多判据,今天我要向大家介绍的是最简单的但是很有效的判据--RGB判 ...