洛谷P2698 [USACO12MAR]花盆Flowerpot】的更多相关文章

P2698 [USACO12MAR]花盆Flowerpot 题目描述 Farmer John has been having trouble making his plants grow, and needs your help to water them properly. You are given the locations of N raindrops (1 <= N <= 100,000) in the 2D plane, where y represents vertical he…
P2698 [USACO12MAR]花盆Flowerpot 一看标签........十分后悔 标签告诉你单调队列+二分了............ 每次二分花盆长度,蓝后开2个单调队列维护最大最小值 蓝后就是code了 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; inline int Max(int a,int b)…
Link: P2698 传送门 Solution: 对于可行区间$[L,R]$,随着$L$的递增$R$不会递减 因此可以使用尺取法来解决此题:不断向右移动左右指针,复杂度保持线性 同时为了维护区间内的最值,要设立两个单调队列来维护最大/最小值 每次当$L$增加时,要从队列头部删去小于$L$的节点(如果后面还有不用管,以后自然会删去) Code: #include <bits/stdc++.h> using namespace std; typedef pair<int,int> P…
https://www.luogu.org/problemnew/show/P2698 警示 用数组写双端队列的话,记得le = 1, ri = 0:le<=ri表示队列非空 题意 求一个最小的区间长度,使得区间中的最大值和最小值的差>=D. 思路 一开始二分加线段树强行做,多了一个log.用ST表可能会优秀.做到nlogn.但是如果用单调队列的话,除去排序,就可以做到O(n)具体来说,对于一个L,合法的最小的右区间若为R,那么L+1的最小合法右区间一定>=R. #include <…
记录每天看(抄)题解的日常: https://www.luogu.org/problem/P2698 我们可以把坐标按照x递增的顺序排个序,这样我们就只剩下纵坐标了: 如果横坐标(l,r)区间,纵坐标的最大值减去最小值大于d,那么就可以更新答案: 看出随着l的增长,r一定是递增的: 可以证明不存在(l2,r2),l2>l1且r2<r,(maxy-miny)>d,且能对答案造成影响: 因为如果有这种存在,那么r2应该是l第一个匹配的对象,是更优的答案: 这就涉及到滑动窗口方法了: 用q1[…
题目描述 Farmer John has been having trouble making his plants grow, and needs your help to water them properly. You are given the locations of N raindrops (1 <= N <= 100,000) in the 2D plane, where y represents vertical height of the drop, and x repres…
P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top…
类型:二分+单调队列 传送门:>Here< 题意:给出$N$个点的坐标,要求根据$x$轴选定一段区间$[L,R]$,使得其中的点的最大与最小的$y$值之差$\geq D$.求$Min\{R-L\}$ 解题思路 一道单调队列的好题 思想依然是转化.我们熟知的单调队列的作用也就是滑动窗口——定长区间滚动最大最小值 但是现在区间长度不固定.容易发现,答案满足单调性的,于是可以二分答案.那么问题就转化为定长区间了.然后维护两个单调队列分别做最大与最小值即可 Code /*By DennyQi 2018…
题目传送门 摩天大楼里的奶牛 题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, th…
题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don't like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, they had a proble…