| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
wa,求解。。。#include<stdio.h>
#define MAX 100010
class imonqueue{//单增队列
public:
int f;
int b;
int queue[MAX];
imonqueue(){f=0;b=0;};
void reset(){b=f=0;};
int front(){if(f>=0) return queue[f];else return -1;};
bool empty(){if(b==f) return true;else return false;};
bool full(){if((b+1)%MAX==f && b>0) return true;else return false;};
void push(int a)
{
if(!full())
{
while(b>0 && a<=queue[b-1])
b--;
queue[b++]=a;
}
};
};
class dmonqueue{//单减队列
public:
int f;
int b;
int queue[MAX];
dmonqueue(){f=0;b=0;};
void reset(){b=f=0;};
int front(){if(f>=0) return queue[f];else return -1;};
bool empty(){if(b==f) return true;else return false;};
bool full(){if((b+1)%MAX==f && b>0) return true;else return false;};
void push(int a)
{
if(!full())
{
while(b>0 && a>=queue[b-1])
b--;
queue[b++]=a;
}
};
};
int main(){
imonqueue imq;
dmonqueue dmq;
int a[MAX],inc[MAX],des[MAX];
int num,k,i,j;
scanf("%d %d",&num,&k);
for(i=0;i<num;i++)
scanf("%d",&a[i]);
num=num-k+1;
for(i=0;i<num;i++)
{
imq.reset();//队列置空
dmq.reset();//队列置空
for(j=i;j<i+k;j++)
imq.push(a[j]),dmq.push(a[j]);
inc[i]=imq.front();
des[i]=dmq.front();
}
for(i=0;i<num;i++) printf("%d ",inc[i]);
printf("\n");
for(i=0;i<num;i++) printf("%d ",des[i]);
printf("\n");
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator