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

求大神搭救...第一次写!但是一直过不了!自己测试了好久没发现错误!但是就是AC不了

Posted by mo__wang at 2013-03-28 19:37:22 on Problem 1442
#include <iostream>
#include <stdio.h>
#include <queue>
#include <vector>
using namespace std;
priority_queue<int,vector<int>,greater<int> > Pmin;
priority_queue<int> Pmax;  //构建一个大顶堆和一个小顶堆的优先队列
int M,N;
int A[3005];		
int u[3005];
int i = 0;
void operater(){
	int K=0;//记录是第k小的数字
	for(int j = 0;j<M;j++){
		K++;
		for(;i<u[j]||Pmax.size()<K;i++){
			if(Pmax.size()<K){
				if(i<u[j]){
					if(!Pmin.empty() && A[i]>Pmin.top())
					{
						Pmax.push( Pmin.top() );
						Pmin.pop();
						Pmin.push(A[i]);
					}
					else Pmax.push(A[i]);
				}
				else if(!Pmin.empty()){
					Pmax.push(Pmin.top());
					Pmin.pop();
					i--;	
				}
				else break;
			}//if
			else {
				if(Pmax.top() > A[i]){
					Pmin.push(Pmax.top());
					Pmax.pop();
					Pmax.push(A[i]);
				}

				else{
					Pmin.push(A[i]);
				}//else
			}//else
		}//for
		cout<<Pmax.top()<<endl;
	}
}

int main()
{

	cin>>N>>M;
	for(int i=0;i<N;i++){//输入一系列数
		cin>>A[i];
	}

	for(int j=0;j<M;j++){//输入
		cin>>u[j];
	}
	operater();
	return 1;
}

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