pku 2823 双端队列
来源:互联网 发布:sql delete加标记 编辑:程序博客网 时间:2024/06/05 03:31
PKU 2823 双端队列特点:
1.队列具有单调性(desc or asc)。
2.只能在对头或队尾进行插入删除操作。
本题维护一个递增和一个递减的两个队列
#include <iostream>#include <stdio.h>#include <deque>#include <vector>using namespace std;int a[1000010];int answer_min[1000010];int answer_max[1000010];int main(){// freopen("in.txt","r",stdin);int n;int k;int i;deque<int> min;deque<int> max;while (scanf("%d%d",&n,&k)!=EOF){ for (i=0; i<n; i++) scanf("%d",&a[i]);min.clear();max.clear();int index = 0;for (i=0; i<n; i++){ while (!min.empty() && a[min.back()] > a[i] ) min.pop_back(); while (!max.empty() && a[max.back()] < a[i]) max.pop_back(); max.push_back(i); min.push_back(i); if (i>=k-1) { answer_max[index] = a[max.front()]; answer_min[index] = a[min.front()]; index++; } if (!min.empty() && i - min.front() == k-1) min.pop_front(); if (!max.empty() && i-max.front() == k-1) max.pop_front();} for (i=0; i<index; i++){ printf("%d",answer_min[i]); if (i == index -1) printf("\n"); else printf(" ");}for (i=0; i<index; i++){ printf("%d",answer_max[i]); if (i == index -1) printf("\n"); else printf(" ");}}return 0;}
- pku 2823 双端队列
- [PKU 2823]Sliding Windows(单调队列版)
- pku 2823(单调队列、线段树)
- PKU 2833 优先队列
- pku 2051 Argus(优先队列)
- 单调队列 - 兼 ACM PKU POJ 3250 及 2823 解题报告
- pku 3635 Full Tank? 优先队列+BFS
- pku 1442 Black Box(优先队列)
- pku 3017 单调队列优化DP
- 队列,优先队列,双端队列
- 队列、双端队列与优先队列
- PKU 2823 Sliding Window
- Java 模拟队列(一般队列、双端队列、优先级队列)
- 栈,队列,双端队列
- 队列与双端队列
- 数据结构(队列):双端队列
- POJ-2823--Sliding Window--双端队列实现单调队列
- PKU 3740 Easy Finding(优先队列)【转帖】
- swjtu oj 1589 Help Alice!
- 非递减顺序表的合并
- ,函数调用问题
- android 2.3 电量管理
- Android自动化测试初探: 模拟键盘鼠标事件(Socket+Instrumentation实现)
- pku 2823 双端队列
- C语言面试题大汇总之华为面试题
- hdu 1022
- android 2.3 wifi (一)
- 第一章, 介绍:挖掘twitter的数据
- android 2.3 wifi (二)
- android 2.3 ethernet
- Erlang vs Java memory architecture
- hdu 1048