poj2823 优先队列
来源:互联网 发布:easyui 表单插件js 编辑:程序博客网 时间:2024/05/22 03:10
简单优先队列
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <cmath>#include <vector>using namespace std;#define maxn 1100000int q[maxn],h,t;int n,m,k,save[maxn],num[maxn];vector<int>ans;void great(){ h=1; t=0; for(int i=1;i<k;i++) { while(h<=t&&q[t]<=save[i]) t--; t++; q[t]=save[i];num[t]=i; } for(int i=k;i<=n;i++) { while(h<=t&&q[t]<=save[i]) t--; t++; q[t]=save[i];num[t]=i; while(num[h]<=i-k)h++; printf("%d ",q[h]); }}void small(){ h=1; t=0; for(int i=1;i<k;i++) { while(h<=t&&q[t]>=save[i]) t--; t++; q[t]=save[i];num[t]=i; } for(int i=k;i<=n;i++) { while(h<=t&&q[t]>=save[i]) t--; t++; q[t]=save[i];num[t]=i; while(num[h]<=i-k)h++; printf("%d ",q[h]); }}int main(){ scanf("%d%d",&n,&k); { for(int i=1;i<=n;i++) { scanf("%d",&save[i]); } small(); printf("\n"); great(); } return 0;}
0 0
- poj2823 优先队列
- poj2823 Sliding Window (优先队列)
- POJ2823 sliding window 优先队列
- poj2823单调队列(模拟优先队列)
- POJ2823 Sliding Window(线段树 ST算法 优先队列)
- poj2823 单调队列
- 单调队列 POJ2823
- 单调队列 (POJ2823)
- POJ2823单调队列
- poj2823单调队列
- POJ2823 单调队列
- poj2823(单调队列)
- poj2823(单调队列)
- 单调队列-poj2823
- POJ2823(单调队列)
- poj2823(单调队列)
- poj2823(单调队列)
- poj2823-单调队列
- Vim实战手册(1)初级个性化配置你的Vim
- 【TOJ 3402】Man Down【SPFA】
- 在共享DLL中使用MFC 和在静态库中使用MFC的区别
- Word Ladder
- 解决游戏中的通货膨胀问题
- poj2823 优先队列
- STL容器
- SVN版本控制
- 为什么ZeroMQ不应该成为你的第一选择
- [水]ZOJ1508
- VS2010出现unsuccessfulbuild”,因为已指定“AlwaysCreate”
- lichee开发板搭建nfs
- 切图
- poj 2573 Bridge (过桥问题 贪心)