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

优先队列可秒,16ms

Posted by 140142 at 2015-07-25 10:11:59 on Problem 3784
贴代码:
#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:
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