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

用两个priority_queue做的,为什么MLE啊?

Posted by structure at 2010-04-27 20:06:24 on Problem 2823
#include<stdio.h>
#include<iostream>
#include<queue>
#include<string.h>
#include"algorithm"
#include<vector>
using namespace std;
bool use[1000100];
struct tt
{
    int ID,num;
}ss;
bool operator <(tt a,tt b)
{
    return a.num<b.num;
}
struct cmp
{
    bool operator()(tt a,tt b)
    {
        return a.num>b.num;
    }
};
struct qq
{
    int max;
}ans[1000100];
int main(int argc, char** argv)
{
    int n,k,i,x,j,kk;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        priority_queue<tt>p;
        priority_queue<tt,vector<tt>,cmp>q;
        for(i=1;i<k;i++)
        {
            scanf("%d",&x);
            ss.ID=i;
            ss.num=x;
            use[i]=0;
            p.push(ss);
            q.push(ss);
        }
        kk=1;
        for(i=k;i<=n;i++)
        {
            scanf("%d",&x);
            ss.ID=i;
            ss.num=x;
            use[i]=0;
            if(kk<=n-k+1)
            {
                for(j=i-k+1;j<=i;j++)
                {
                    p.push(ss);
                    q.push(ss);
                }
                while(!p.empty())
                {
                    tt aa;                
                    aa=p.top();
                    if(!use[aa.ID])
                    {
                        ans[kk].max=aa.num;
                        break;
                    }
                    p.pop();
            
                }
                while(!q.empty())
                {
                    tt bb;
                    bb=q.top();
                    if(!use[bb.ID])
                    {
                        printf("%d",bb.num);
                        if(kk<n-k+1)printf(" ");
                        break;
                    }
                    q.pop();
                }
                use[kk]=1;
                kk++;
            }
        }
        printf("\n");
        for(i=1;i<=n-k+1;i++)
        {
            printf("%d",ans[i].max);
            if(i<n-k+1)printf(" ");
        }
        printf("\n");
    }
    return (EXIT_SUCCESS);
}

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