BZOJ : [Usaco2013 Nov]Crowded 单调队列】的更多相关文章

正反两遍个来一次单调队列 DP 即可. Code: #include<cstdio> #include<deque> #include<algorithm> using namespace std; const int maxn = 50000+3; int mark[maxn]; struct Node{ long long pos,height; Node(long long pos=0,long long height=0):pos(pos),height(hei…
从左到右扫一遍, 维护一个单调不递减队列. 然后再从右往左重复一遍然后就可以统计答案了. ---------------------------------------------------------------------------- #include<bits/stdc++.h>   #define rep(i, n) for(int i = 0; i < n; ++i) #define clr(x, c) memset(x, c, sizeof(x)) #define for…
3314: [Usaco2013 Nov]Crowded Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 86  Solved: 61[Submit][Status] Description Farmer John's N cows (1 <= N <= 50,000) are grazing along a one-dimensional fence. Cow i is standing at location x(i) and has…
3314: [Usaco2013 Nov]Crowded Cows Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 111  Solved: 79[Submit][Status][Discuss] Description Farmer John's N cows (1 <= N <= 50,000) are grazing along a one-dimensional fence. Cow i is standing at location x(…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3314 题意: N头牛在一个坐标轴上,每头牛有个高度.现给出一个距离值D. 如果某头牛在它的左边,在距离D的范围内,如果找到某个牛的高度至少是它的两倍,且在右边也能找到这样的牛的话.则此牛会感觉到不舒服. 问有多少头会感到不舒服. 题解: 从左到右.从右到左两遍单调队列. 单调性: (1)坐标x递增. (2)高度h递减. 维护单调性: (1)从队首开始,所有与当前牛i的距离超过d的,以后都…
第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define N 50010 using namespace std; struct data { int x,h; }a[N],q[N]; int n,m,l,r; int ok1[N],ok2[N]; inline int read() { ,ans…
Description 给你一个n长度的数轴和m个区间,每个区间里有且仅有一个点,问能有多少个点 Input * Line 1: Two integers N and M. * Lines 2..M+1: Line i+1 contains a_i and b_i. Output * Line 1: The maximum possible number of spotted cows on FJ's farm, or -1 if there is no possible solution. S…
洛谷传送门 题目大意:给你一个长度为$n$的序列和$m$个区间,每个区间内有且仅有一个1,其它数必须是0,求整个序列中数字1最多的数量 神题,竟然是$DP$ 定义$f_{i}$表示第i位放一个1时,最多的1的数量 因为每个区间至少一个点,如果要在$i$位置放一个1,显然在$i$左侧没覆盖$i$的区间中,选择一个位置$j$,$j$必须保证如果在$j$放一个1,那么它右侧没有空区间再需要放1,显然$j$是没覆盖i的区间中最大的左端点,维护一个数组$l_{i}$,表示最左端能转移的区间 因为每个区间至…
3126: [Usaco2013 Open]Photo Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 374  Solved: 188[Submit][Status][Discuss] Description Farmer John has decided to assemble a panoramic photo of a lineup of his N cows (1 <= N <= 200,000), which, as always,…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1047 题意:见中文题面 思路:该题是求二维的子矩阵的最大值与最小值的差值尽量小.所以可以考虑求出每个子矩阵的最大值和最小值.考虑一维求子段的最小值/最大值的思路.滑动窗口+单调队列. 转换成二维.设minNum[i][j]表示右下角为(i,j)的子矩阵的最小值.先对矩阵每一行用一维的做法求出每一行的子段的最小值,然后同样的方法求列的最值.注意在求列的子段最小值时比较的元素不是原矩阵的元素…