| ||||||||||
| 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 | |||||||||
我用队列来做,超时了,大牛帮我改进一下,在此谢过!!!#include<iostream>
#include<queue>
#define MIN 1000000
#define MAX -1000000
using namespace std;
int min2[1000000],max2[1000000];
int main(){
queue<int> p;
int n,k ,i,j =1,x,len;
scanf("%d%d",&n,&k);
int min1,max1,lenmin = 0,lenmax = 0;
min1 = MIN;
max1 = MAX;
for(i=0;i<k;i++)
{
scanf("%d",&x);
if(x>max1)
max1 = x;
if(x<min1)
min1 = x;
p.push(x);
}
while(i<n){
min2[lenmin++] = min1;
max2[lenmax++] = max1;
x = p.front();
len = k-1;
if(min1 == x||max1==x){
p.pop();
min1 = MIN;
max1 = MAX;
while(len>0){
x = p.front();
if(x>max1)
max1 = x;
if(x<min1)
min1 = x;
len--;
p.push(x);
p.pop();
}
}
else
p.pop();
scanf("%d",&x);
if(x>max1)
max1 = x;
if(x<min1)
min1 = x;
p.push(x);
i++;
}
min2[lenmin++] = min1;
max2[lenmax++] = max1;
for(i = 0;i<lenmin;i++)
printf("%d ",min2[i]);
printf("\n");
for(i = 0;i<lenmax;i++)
printf("%d ",max2[i]);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator