传送门

题目大意

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

分析

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

    spring表达式SpEL 语法#{..},为bean的属性进行动态赋值 通过bean的id对bean进行引用 调用方法以及引用对象中的属性 计算表达式的值 正则表达式的匹配 修改Address.ja ...

  2. Android Studio 开始运行错误

    /******************************************************************************** * Android Studio 开 ...

  3. PHP学习之数组Array操作和键值对操作函数(一)

    PHP 中的数组实际上是一个有序映射.映射是一种把 values关联到 keys 的类型.此类型在很多方面做了优化,因此可以把它当成真正的数组,或列表(向量),散列表(是映射的一种实现),字典,集合, ...

  4. 滑雪(经典DP思想)

    个人心得:思想还是不够,开始自己写但是不知道如何记录长度,也不太知道状态的转移,后面看了百度, 发现人人为我我为人人就是一步一步推导, 而递归思想就要求学会记录和找到边界条件,这一题中的话就是用递归, ...

  5. Unity之将Texture保存成png

    http://blog.csdn.net/bingheliefeng/article/details/51177505 using UnityEngine;using System.Collectio ...

  6. ExtJs中获得当前选中行号(Grid中多选或者是单选)及Grid的反选(取消选中行)

    多选,如何获得每行的行号: function getlineNum(){    var sm=titleGird.getSelectionModel(); // 获得grid的SelectionMod ...

  7. 蓝桥杯 基础练习 BASIC-24 龟兔赛跑预测

    基础练习 龟兔赛跑预测   时间限制:1.0s   内存限制:512.0MB 问题描述 话说这个世界上有各种各样的兔子和乌龟,但是研究发现,所有的兔子和乌龟都有一个共同的特点——喜欢赛跑.于是世界上各 ...

  8. 机器学习:集成学习(OOB 和 关于 Bagging 的更多讨论)

    一.oob(Out - of - Bag) 定义:放回取样导致一部分样本很有可能没有取到,这部分样本平均大约有 37% ,把这部分没有取到的样本称为 oob 数据集: 根据这种情况,不对数据集进行 t ...

  9. sql语句中GROUP BY 和 HAVING的使用 count()

    在介绍GROUP BY 和 HAVING 子句前,我们必需先讲讲sql语言中一种特殊的函数:聚合函数, 例如SUM, COUNT, MAX, AVG等.这些函数和其它函数的根本区别就是它们一般作用在多 ...

  10. 2015 浙江省赛 H - May Day Holiday

    H - May Day Holiday As a university advocating self-learning and work-rest balance, Marjar Universit ...