Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

wa,求解。。。

Posted by ujn_20101221123 at 2012-07-20 10:36:49 on Problem 2823
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator