poj2823
来源:互联网 发布:硕鼠mac 版下载 编辑:程序博客网 时间:2024/06/06 06:47
//优先队列读入的是id,但是是按照id对应的数排完序的
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int a[1000000];
int aa[1000000];
int bb[1000000];
int n,s;
//这次让我见识到了队列的另外比较高级一点的用法,还可以这样用,第一次见到啊。
struct cmp1
{
bool operator()(const int a1,const int a2)
{
return a[a1]>a[a2];
}
};
struct cmp2
{
bool operator()(const int a1,const int a2)
{
return a[a1]<a[a2];
}
};
//就这里比较高级,比较函数竟然是个结构类型的。
priority_queue<int,vector<int>,cmp1>q1;
priority_queue<int,vector<int>,cmp2>q2;
int main()
{
scanf("%d%d",&n,&s);
int i,cnt1=0,cnt2=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<s;i++)
{
q1.push(i);
q2.push(i);
}
aa[cnt1++]=a[q1.top()];
bb[cnt2++]=a[q2.top()];
for(i=s;i<n;i++)
{
q1.push(i);
q2.push(i);
while(i-q1.top()>=s)
q1.pop();
aa[cnt1++]=a[q1.top()];
while(i-q2.top()>=s)
q2.pop();
bb[cnt2++]=a[q2.top()];
}
printf("%d",aa[0]);
for(i=1;i<n-s+1;i++)
printf(" %d",aa[i]);
printf("/n");
printf("%d",bb[0]);
for(i=1;i<n-s+1;i++)
printf(" %d",bb[i]);
printf("/n");
return 0;
}
- poj2823
- POJ2823
- poj2823
- poj2823
- POJ2823
- poj2823
- poj2823
- POJ2823
- poj2823
- POJ2823
- POJ2823
- poj2823(ST)
- poj2823(堆)
- poj2823 单调队列
- 单调队列 POJ2823
- 單調隊列::poj2823 Sliding Window
- poj2823 Sliding Window
- 单调队列 (POJ2823)
- VC6 STL使用时候很多warning, stl使用以及消除warning的方法如下
- 关于DataAdapter的update方法错误现象的解释
- JS倒计时代码
- JFreeChart图形报表引擎入门实例讲解
- OnPaint()函数的作用原理
- poj2823
- XML 查询,读,写,删,加
- ICE 网络库尝试
- SPIN
- Office2000下内部COM插件的编程实现
- Oracle自增ID实现[网摘]
- 引用类型(重量级对象)和值类型(轻量级对象)
- c# 正在迷惑,想用一个类来专门存放方法,另几个类都可以调用
- STL 算法基本概念