Ural 1126. Magnetic Storms
2013-08-01 21:46
288 查看
题好难读,输出长度为k的区间内的峰值。
单调队列的应用。
单调队列的插入就是把一个元素加入,从队尾开始到比第一个他的大的元素位置之后,在之后的元素全部抛弃。
删除就是从对头找到第一个满足可在队列中的元素作为对头。
单调队列的应用。
单调队列的插入就是把一个元素加入,从队尾开始到比第一个他的大的元素位置之后,在之后的元素全部抛弃。
删除就是从对头找到第一个满足可在队列中的元素作为对头。
#include <iostream> #include <cstdio> #include <cstring> #include <map> #include <set> #include <stack> #include <queue> using namespace std; const int maxn=25010; int RMax[maxn],pos[maxn]; int main() { //freopen("data","r",stdin); int n,m; scanf("%d",&m); int l=0,r=0,t=0;//head and tail while(scanf("%d",&n)&&n!=-1) { //cout<<"t="<<t<<endl; t++; while(l>=r)// into queue { if(l>=0&&RMax[l]<=n) { l--; } else break; } RMax[++l]=n; pos[l]=t; while(pos[r]+m<=t) { r++; } //cout<<t<<" "<<m<<endl; if(t>=m) { printf("%d\n",RMax[r]); } } return 0; }
相关文章推荐
- Ural 1126. Magnetic Storms
- ural 1126 Magnetic Storms
- Ural1126-Magnetic Storms
- Ural 1126 Magnetic Storms
- Ural 1126. Magnetic Storms 单调队列
- ural 1126. Magnetic Storms(双向队列)
- Ural 1126. Magnetic Storms
- Ural_1126. Magnetic Storms 单调队列
- ural 1126. Magnetic Storms
- ural 1126
- ural 1126【单调队列基础】
- 1126. Magnetic Storms(单调队列)
- 1126. Magnetic Storms(单调队列)
- 1126. Magnetic Storms(单调队列)
- 【URAL 刷题记】URAL 1600 ~ URAL 1607
- URAL1297 Palindrome(后缀数组)
- ural 2067. Friends and Berries
- URAL 1146 Maximum Sum(最大子矩阵的和 DP)
- lightoj 1126 - Building Twin Towers DP
- URAL 1992 CVS