poj 2051

优先队列或者说是堆得应用,最暴力的想法就是没输出一个最小值,更新,然后再排序,若用快排,时间效率为O(knlgn),但不需要对所有的排次序,所以就用到最小堆

#include <iostream>
#include <queue>
#include <string>
using namespace std;
typedef struct node
{
	int n,p,r;
}ar;
bool operator<(ar a,ar b)
{
	if(a.p==b.p) return a.n>b.n;
	else
		return a.p>b.p;
}
priority_queue<ar> q;
int main()
{
	string re;
	int n,p,k;
	while(cin>>re)
	{
		if(re=="#") break;
		cin>>n>>p;
		ar tem1;
		tem1.n=n;
		tem1.p=p;
		tem1.r=p;
		q.push(tem1);
	}
	cin>>k;
	while(k--)
	{
		ar tem2;
		tem2=q.top();
		cout<<tem2.n<<endl;
		tem2.p+=tem2.r;
		q.pop();
		q.push(tem2);
	}
	return 0;
}


 

 

转载于:https://www.cnblogs.com/lj-vs-lishimin/archive/2012/10/18/2774374.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值