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

优先队列188MS~~菜鸟求指点~~

Posted by GreenBird at 2011-03-22 00:32:28 on Problem 1442
#include<cstdio>
#include<queue>
using namespace std;
struct cmp1
{
	bool operator()(const int a,const int b)
	{
		return a>b;
	}
};
struct cmp2
{
	bool operator()(const int a,const int b)
	{
		return a<b;
	}
};
priority_queue<int,vector<int>,cmp1>q1;
priority_queue<int,vector<int>,cmp2>q2;
int a[30000],u,i;
int main()
{
	int m,n,c=0,t;
	scanf("%d%d",&m,&n);
	for(i=0;i<m;i++)scanf("%d",&a[i]);
	for(i=0;i<n;i++){
		scanf("%d",&u);
		while(c<u){
			q1.push(a[c]);
			if(!q2.empty()&&q1.top()<q2.top()){
				t=q1.top();
				q1.pop();
				q1.push(q2.top());
				q2.pop();
				q2.push(t);
			}
			c++;
		}
		printf("%d\n",q1.top());
		q2.push(q1.top());
		q1.pop();
	}
}

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