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 |
优先队列可秒,16ms贴代码: #include<queue> #include<vector> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; priority_queue<int,vector<int>,greater<int> >miq; priority_queue<int,vector<int>,less<int> >maq; void init() { while(!miq.empty()) miq.pop(); while(!maq.empty()) maq.pop(); } int main() { int c,T,n,m,i,j,k,x; scanf("%d",&T); for(c=1;c<=T;c++) { init(); scanf("%d%d",&i,&n); printf("%d %d\n",c,n/2+(n&1?1:0)); scanf("%d",&x); printf("%d",x); maq.push(x); for(i=2,j=1;i<=n;i++) { scanf("%d",&x); if(maq.top()>=x) maq.push(x); else miq.push(x); if(i&1) { if(j==10) putchar('\n'),j=0; else putchar(' '); printf("%d",maq.size()>miq.size()?maq.top():miq.top()); j++; } else { if(maq.size()>miq.size()) { miq.push(maq.top()); maq.pop(); } if(maq.size()<miq.size()) { maq.push(miq.top()); miq.pop(); } } } putchar('\n'); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator