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

求解为什么TLE(排序贪心+堆)

Posted by sdfzyhx at 2016-02-16 15:26:38 on Problem 1456
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
struct product
{
	int p,d;
}a[10010],p1,p2;
struct cmp_queue
{
	bool operator()(const product & a,const product & b)
	{
		return a.p>b.p;
	}
};
bool cmp_array(const product & a,const product & b)
{
	return a.d<b.d;
}
priority_queue<product,vector<product>,cmp_queue> q;
int main()
{
	int i,j,k,m,n,x,y,z,t;
	while (scanf("%d",&n))
	{
		memset(a,0,sizeof(a));
		for (i=1;i<=n;i++)
		  scanf("%d%d",&a[i].p,&a[i].d);
		sort(a+1,a+n+1,cmp_array);
		for (i=1;i<=n;i++)
		{
			if (q.size()<a[i].d)
			  q.push(a[i]);
			else
			  if (a[i].p>q.top().p)
			  {
			  	q.pop();
			  	q.push(a[i]);
			  }
		}
		t=0;
		while (!q.empty())
		{
			p1=q.top();
			q.pop();
			t+=p1.p;
		}
		printf("%d\n",t);
	}
}

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