[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)…
类型:二分+单调队列 传送门:>Here< 题意:给出$N$个点的坐标,要求根据$x$轴选定一段区间$[L,R]$,使得其中的点的最大与最小的$y$值之差$\geq D$.求$Min\{R-L\}$ 解题思路 一道单调队列的好题 思想依然是转化.我们熟知的单调队列的作用也就是滑动窗口——定长区间滚动最大最小值 但是现在区间长度不固定.容易发现,答案满足单调性的,于是可以二分答案.那么问题就转化为定长区间了.然后维护两个单调队列分别做最大与最小值即可 Code /*By DennyQi 2018…
Link: P2698 传送门 Solution: 对于可行区间$[L,R]$,随着$L$的递增$R$不会递减 因此可以使用尺取法来解决此题:不断向右移动左右指针,复杂度保持线性 同时为了维护区间内的最值,要设立两个单调队列来维护最大/最小值 每次当$L$增加时,要从队列头部删去小于$L$的节点(如果后面还有不用管,以后自然会删去) Code: #include <bits/stdc++.h> using namespace std; typedef pair<int,int> P…
单调队列+二分答案 #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> using namespace std; struct Node{ int x, y; }nd[100005]; int n, d, ans, q1[100005], q2[100005], l1, r1, l2, r2; bool cmp(Node u, Node v){ retur…
题目链接 Solution 转化一下,就是个单调队列. 可以发现就是一段区间 \([L,R]\) 使得其高度的极差不小于 \(d\) ,同时满足 \(R-L\) 最小. 然后可以考虑二分然后再 \(O(n)\) 判断, 时间复杂度 \(O(nlogn)\) . Code #include<bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f using namespace std; const int maxn=1000008;…
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 <…
题目描述 首先我们简化一下题意: 要找一段区间[L,R],使区间[L,R]内元素最大值减最小值大于等于D. 做法: 首先很容易想到采用二分,分什么呢? 我们二分区间长度为mid 这个时候,检验就成为了我们的目标 最暴力的检验就是枚举左端点,在区间内找最大和最小,有一个max-min>=D 让我们模拟一下: 假如mid=2: (1) [1,3] (2) [2,4] (3) [3 5] (4) ..... 我们震惊的发现:P1886 滑动窗口 这貌似有点相似 于是正解出现了 正解: 二分区间长度为m…
记录每天看(抄)题解的日常: https://www.luogu.org/problem/P2698 我们可以把坐标按照x递增的顺序排个序,这样我们就只剩下纵坐标了: 如果横坐标(l,r)区间,纵坐标的最大值减去最小值大于d,那么就可以更新答案: 看出随着l的增长,r一定是递增的: 可以证明不存在(l2,r2),l2>l1且r2<r,(maxy-miny)>d,且能对答案造成影响: 因为如果有这种存在,那么r2应该是l第一个匹配的对象,是更优的答案: 这就涉及到滑动窗口方法了: 用q1[…
刷水~ Code: #include<bits/stdc++.h> using namespace std; #define setIO(s) freopen(s".in","r",stdin) #define maxn 300000 #define inf 1000000 deque<int>p,q; struct Node { int x,y; }nd[maxn]; bool cmp(Node a, Node b) { return a.…
[USACO12MAR]花盆 二分 单调队列 存在一个长度为\(x\)的区间\([l,r]\),使得区间中最大值与最小值差至少为\(w\),求这个最小的\(x\) \(n\le 100000\),\(w\le 1000000\) 显然区间长度\(x\)越大,最值之差越大,满足单调性,上二分答案,问题转化为是否存在长度为\(mid\)的区间中最值之差至少为\(w\),而这个问题可以用单调队列(滑动窗口)\(O(n)\)解决. 单调队列存的下标,首先判断队首是否合法(窗口大小),然后按照"比你强还比…
题目描述 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…
因为本蒻实在太蒻了...对于即将到来的NOIP2018ssfd,所以下决心要把自己近期做过的题目(衡量标准为洛谷蓝题难度或以上)整理一下,归归类,简单地写一下思路,就当作自己复习了吧qwq 本随笔持续更新,自2018.9.19开始,计划更新到2018NOIP截止 (但是因为最近写的比赛题比较多..但是没有办法把这些题放上来..所以只能放上主流OJ上面有的题) 如果本蒻今年有幸没有AFO掉,flag先里在这里--之后学省选知识点的时候会重开一贴更新的,到时候希望是更有难度的题目吧. 搜索 [NOI…
搜索 [NOIP2013]华容道 最短路+带剪枝的搜索,是一个思维难度比较大的题目. CF1064D Labyrinth 考虑贪心,用双向队列bfs [NOIP2017]宝藏 剪枝搜索出奇迹 题解:https://www.cnblogs.com/fengxunling/p/9777606.html luogu 有趣的数 [ZJOI2007] 时态同步 [NOIP2002] 矩形覆盖 这题数据太水... 题解:https://www.cnblogs.com/fengxunling/p/984161…
https://www.luogu.org/problemnew/show/P2698#sub 老板需要你帮忙浇花.给出N滴水的坐标,y表示水滴的高度,x表示它下落到x轴的位置. 每滴水以每秒1个单位长度的速度下落.你需要把花盆放在x轴上的某个位置,使得从被花盆接着的第1滴水开始,到被花盆接着的最后1滴水结束,之间的时间差至少为D. 我们认为,只要水滴落到x轴上,与花盆的边沿对齐,就认为被接住.给出N滴水的坐标和D的大小,请算出最小的花盆的宽度W. 单调队列好题,参考洛谷题解. emm……显然是…
描述 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 represen…
洛谷题目链接:[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…
题目:http://172.21.85.56/oj/exercise/problem?problem_id=21568 题目大意:老板需要你帮忙浇花.给出N滴水的坐标,y表示水滴的高度,x表示它下落到x轴的位置. 每滴水以每秒1个单位长度的速度下落.你需要把花盆放在x轴上的某个位置,使得从被花盆接着的第1滴水开始,到被花盆接着的最后1滴水结束,之间的时间差至少为D. 我们认为,只要水滴落到x轴上,与花盆的边沿对齐,就认为被接住.给出N滴水的坐标和D的大小,请算出最小的花盆的宽度W 分析:使用神奇…
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…
NC24325 [USACO 2012 Mar S]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 ve…
题目描述 给出n个物品,体积为w[i],现把其分成若干组,要求每组总体积<=W,问最小分组.(n<=18) 输入格式: Line 1: N and W separated by a space. Lines 2..1+N: Line i+1 contains the integer C_i, giving the weight of one of the cows. 输出格式: Line 1: A single integer, R, indicating the minimum number…
我旁边有一个暴力的金牌爷整天欺负我嘤嘤嘤 关我电脑,关我浏览器,还钦定我学不会贪心 没错我就是学不会了 这道题还是非常妙的 我们发现这个土的数量实在是少的可怜,于是我们甚至可以对每一个单位的土都进行贪心 分成两种情况考虑 当前的\(a_i<b_i\),我们还需要往这个位置补一些土,可能是从前面某一个位置拿一些过来,也有可能就是用\(x\)一个单位的代价往这个位置补 \(a_i>b_i\),我们需要去掉一些土,可能是将一些位置的土给拿过来,也有可能就是用\(y\)一个单位的代价往外丢 还有一条非…
题目传送门 摩天大楼里的奶牛 题目描述 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…
题目链接 状压\(dp\) 根据套路,先设\(f[sta]\)为状态为\(sta\)时所用的最小分组数. 可以发现,这个状态不好转移,无法判断是否可以装下新的一个物品.于是再设一个状态\(g[sta]\)表示状态为\(sta\)时 每组剩下的体积的最大值 的最大值,当枚举状态为\(sta\),枚举到第\(i\)个时,可以得到\(g\)的转移: \[ g[v]=max(g[v],g[sta]-w[i]) \] 其中,\(v​\)为转移后的状态. 然后每次就可以根据\(g\)来转移\(f\)了. #…
题目描述 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…
题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle of the field. His cows, always up to no good, decide to play a prank of Farmer John: they deposit N bales of hay (1 <= N <= 50,000) at various locati…
https://www.luogu.org/problemnew/show/P1849 题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle of the field. His cows, always up to no good, decide to play a prank of Farmer John: they deposit N bales…
传送门 神奇的spfa #include <queue> #include <cstdio> #include <cstring> #include <iostream> #define N 1010 #define max(x, y) ((x) > (y) ? (x) : (y)) int n, mx, my; int dis[N][N]; bool map[N][N], vis[N][N]; int dx[4] = {0, -1, 0, 1}, d…
题目描述 After a long day of work, Farmer John completely forgot that he left his tractor in the middle of the field. His cows, always up to no good, decide to play a prank of Farmer John: they deposit N bales of hay (1 <= N <= 50,000) at various locati…
题目描述 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…