269D Maximum Waterfall
题目大意
给出一些墙,水从高往低流,每次只能到达一面墙,选择一个路径,使得路径上的流量的最小值最大。
分析
这是一道经典的扫描线题,我们发现能够合法的线段对数至多只有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的更多相关文章
- POJ3693 Maximum repetition substring [后缀数组 ST表]
Maximum repetition substring Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9458 Acc ...
- Uncaught RangeError: Maximum call stack size exceeded 调试日记
异常处理汇总-前端系列 http://www.cnblogs.com/dunitian/p/4523015.html 开发道路上不是解决问题最重要,而是解决问题的过程,这个过程我们称之为~~~调试 记 ...
- 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.免费应用程序调试最 ...
- MTU(Maximum transmission unit) 最大传输单元
最大传输单元(Maximum transmission unit),以太网MTU为1500. 不同网络MTU如下: 如果最大报文数据大小(MSS)超过MTU,则会引起分片操作. 路径MTU: 网路 ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- [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 ...
- [LeetCode] Third Maximum Number 第三大的数
Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...
- [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 ...
- [LeetCode] Create Maximum Number 创建最大数
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum numb ...
随机推荐
- nginx中关于并发数的问题worker_connections,worker_processes
我认为,要搞清楚这个公式是否正确,以及如何计算的,那首先要对nginx的各个配置说明有清晰的认识: 从用户的角度,http 1.1协议下,由于浏览器默认使用两个并发连接,因此计算方法: nginx作为 ...
- pip镜像源
pip是用国内镜像源 https://pypi.python.org/http://pypi.douban.com/simple/ http://mirrors.aliyun.com/pypi/sim ...
- 2016 ACM-ICPC EC-Final题解
题目链接 A. Number Theory Problem 题意:给你一个数N,求形如2k-1且小于2N的数中有多少能被7整除. 解法:观察二进制位找规律,答案是N/3. #include<bi ...
- 难道调用ThreadPool.QueueUserWorkItem()的时候,真是必须调用Thread.Sleep(N)吗?
开门见山,下面的例子中通过调用ThreadPool.QueueUserWorkItem(WaitCallback callBack, object state)的方式实现异步调用: 1: class ...
- think python chapter2
1.An assignment statement creates a new variable and gives it a value: Variable names can be as long ...
- testng监听ISuiteListener
实现ISuiteListener public class TestNgBeforeAction implements ISuiteListener{ public void onStart(ISui ...
- div 遮罩层 弹窗
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Poj 2395 Out of Hay( 最小生成树 )
题意:求最小生成树中最大的一条边. 分析:求最小生成树,可用Prim和Kruskal算法.一般稀疏图用Kruskal比较适合,稠密图用Prim.由于Kruskal的思想是把非连通的N个顶点用最小的代价 ...
- vijos1264:神秘的咒语
描述 身为拜月教的高级间谍,你的任务总是逼迫你出生入死.比如这一次,拜月教主就派你跟踪赵灵儿一行,潜入试炼窟底. 据说试炼窟底藏着五行法术的最高法术:风神,雷神,雪妖,火神,山神的咒语.为了习得这些法 ...
- HDFS之三:hdfs参数配置详解
1.hdfs-site.xml 参数配置 – dfs.name.dir – NameNode 元数据存放位置 – 默认值:使用core-site.xml中的hadoop.tmp.dir/dfs/nam ...