ural 1126【单调队列基础】
2011-08-06 15:16
453 查看
http://acm.timus.ru/problem.aspx?space=1&num=1126
虽说是简单的单调队列,但是足足折磨了我大半天!因为没接触过单调队列,所以刚开始时束手无策,可以用线段树,但你知道线段树的代码量。。。
题意是给出一个数列,给出一个n,问你每n个连续的数中最大的是多少。
具体做法参考我博客这里。
代码实现:本人用了STL的deque
虽说是简单的单调队列,但是足足折磨了我大半天!因为没接触过单调队列,所以刚开始时束手无策,可以用线段树,但你知道线段树的代码量。。。
题意是给出一个数列,给出一个n,问你每n个连续的数中最大的是多少。
具体做法参考我博客这里。
代码实现:本人用了STL的deque
#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <string.h> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <limits.h> using namespace std; int lowbit(int t){return t&(-t);} int countbit(int t){return (t==0)?0:(1+countbit(t&(t-1)));} int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);} int max(int a,int b){return a>b?a:b;} int min(int a,int b){return a>b?b:a;} #define LL __int64 #define pi acos(-1) #define N 100010 #define INF INT_MAX #define eps 1e-8 #define FRE freopen("a.txt","r",stdin) struct node { int num; int id; }; deque<node> de; int main() { // FRE; int n; scanf("%d",&n); int cnt=1; node p; de.clear(); while(scanf("%d",&p.num)&&p.num!=-1) { p.id=cnt; while(!de.empty()&&de.front().id<cnt-n+1 ) {de.pop_front();} while(!de.empty()&&de.back().num<p.num) {de.pop_back();} cnt++; de.push_back(p); if(cnt>n) printf("%d\n",de.front().num); } return 0; }
相关文章推荐
- Ural_1126. Magnetic Storms 单调队列
- Ural 1126. Magnetic Storms 单调队列
- 【基础练习】【单调队列和其他】10.19.2015校内测试总结
- ural 1126. Magnetic Storms(双向队列)
- 单调栈及单调队列基础与运用
- 单调队列(基础题) HDU3706 Second My Problem First
- 1126. Magnetic Storms(单调队列)
- hdu3706基础的单调队列
- URAL 1427. SMS(DP+单调队列)
- #POJ2823#Sliding Window (单调队列基础)
- hdu 2191 多重背包基础题以及(单调队列O(vm))的用法
- 单调队列:基础
- #HDU3415#Max Sum of Max-K-sub-sequence(单调队列基础)
- 1126. Magnetic Storms(单调队列)
- 1126. Magnetic Storms(单调队列)
- 【算法学习笔记】53.单调队列的简单应用 SJTU OJ 1034 二哥的金链
- [luoguP1440] 求m区间内的最小值(单调队列 || 线段树)
- POJ 2823 Sliding Window <速度特快 单调队列>
- 【单调队列】bzoj2096 [Poi2010]Pilots
- 两种解法-树形dp+二分+单调队列(或RMQ)-hdu-4123-Bob’s Race