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 |
用两个priority_queue做的,为什么MLE啊?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator