传送门

题目大意

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

分析

这是一道经典的扫描线题,我们发现能够合法的线段对数至多只有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. HttpClient与Spring RestTemplate

    需要的包 ,除了Spring的基础包外还用到json的包,这里的数据传输使用json格式 客户端和服务端都用到一下的包 <!-- Spring --> <dependency> ...

  2. 魔法效果——dijkstra+堆(邻接表存储)

    dijkstra本身每次要for一遍,才能找出最小的节点,但用了堆之后,直接取出堆首就可以了. 但要注意的一点是,c++自带的stl里的priority_queue本身是先入大出的,而我们要求的是最小 ...

  3. 让camera实现类似cs第一人称视角旋转和位移

    直接把这个脚本挂在摄像机上就可: using System.Collections; using System.Collections.Generic; using UnityEngine; /* * ...

  4. 总结的一些MySQL数据库面试题

    1.sql语句应该考虑哪些安全性? 1.防止sql注入,对特殊字符进行转义,过滤或者使用预编译的sql语句绑定变量. 2.最小权限原则,特别是不要用root账户,为不同的类型的动作或者组建使用不同的账 ...

  5. vue切换样式

    在vue中使用事件来切换绑定的class样式,在vue-cli脚手架中的Home.vue中 <template> <div id="main"> <l ...

  6. oracle如何insert into 多个values

    稍微熟悉Oracle的都知道,如果我们想一条SQL语句向表中插入多个值的话,如果如下语句 INSERT INTO 某表 VALUES(各个值),VALUES(各个值),.....; 这样会报错的,因为 ...

  7. 异常:java.lang.IllegalStateException: No instances found of configserver(里面是一个微服务名)

    今天本地测试代码时出现了个异常,该异常出现的原因是:微服务启动的顺序出现了问题: 应该先启动本地eureka,然后在启动本地配置中心,然后在启动具体的微服务.

  8. eclipse -- propedit 安装.

    SSH 项目中.用到国际化文件,Message.properties 但里面的文本都是 unicode 格式的,用起来不谁.而且也不想通过其它工具转码来使用. 可以通过安装 eclipse 的 pro ...

  9. 在Mac系统下如何恢复SourceTree全局忽略的文件

    在家目录“~”下编辑 “.gitignore_global ” 文件即可:vim  .gitignore_global

  10. GUI练习中

    总结:JFrame和Frame是有很大差别的. 不要混淆.否则方法是不能成功调用的 特别是背景色:JFrame.对象f在main里无法调用背景色前景色都不想显示 一下是书上的一段代码,编译错误,但是可 ...