Strip CodeForces - 487B (单调队列)】的更多相关文章

题面: Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The di…
有一个数列,对于每一个数,求比它小的在他右边距离他最远的那个数和他的距离 用单调队列做,维护单调队列时可采用如下方法,对于每一个数,如果队列中没有数,则加入队列,如果队列头的数比当前数大,则舍弃该数 对于此题,可用两个队列来维护,一个保存值,一个保持位置,每次查询对值进行二分,然后到对应保持位置的队列中求出结果 #include<map> #include<set> #include<cmath> #include<queue> #include<st…
F. Cutlet time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it…
题目链接 Strip 题意   把一个数列分成连续的$k$段,要求满足每一段内的元素最大值和最小值的差值不超过$s$, 同时每一段内的元素个数要大于等于$l$, 求$k$的最小值. 考虑$DP$ 设$dp[i]$为前$i$个数字能划分成区间个数的最小值. 则$dp[i] = min(dp[j] + 1)$ 于是下一步就是求符合条件的j的范围. 构建$ST$表,支持区间查询最大值和最小值. 对于每一个位置$x$,我们知道$max(a[i]...a[x]) - min(a[i]...a[x])$肯定…
B - Strip 思路:简单dp,用st表+单调队列维护一下. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define y1 skldjfskldjg #define y2 skldfjsklejg using namespace std; ; ; const int…
B. Ancient Berland Hieroglyphs 题目连接: http://codeforces.com/problemset/problem/164/B Descriptionww.co Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hierog…
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/319/B Description There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who h…
题目链接: http://codeforces.com/contest/6/problem/E E. Exposition time limit per test 1.5 secondsmemory limit per test 64 megabytes 问题描述 There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection th…
题目链接:http://codeforces.com/problemset/problem/455/A 题目大意:有n个数,每次可以选择删除一个值为x的数,然后值为x-1,x+1的数也都会被删除,你可以获得分值x,求出能获得的最大分值为多少. 解题思路:从小到大排序,去重一下, 用cnt[i]记录一下数字i出现次数.那么可以得到状态转移方程:dp[i]=max(dp[i],dp[j]+cnt[i]*a[i])(j<i&&a[i]-a[j]>1),再用单调队列优化一下就行了O(∩…
题目链接:http://codeforces.com/problemset/problem/1029/B 题目大意:从数组a中选出一些数组成数组b,要求 b[i+1]<=b[i]*2 . 一开始想到的是O(n^2)的动态规划,但是超时了,下面是超时的代码. #include <iostream> using namespace std; const int maxn = 200020; int n, a[maxn], f[maxn], res = 0; int main() { cin…