现在的位置: 首页 > 综合 > 正文

priority_queue的使用

2013年05月11日 ⁄ 综合 ⁄ 共 401字 ⁄ 字号 评论关闭

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2126


典型例题,优先队列还有很多的用处,暂未开发。


#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m)
	{
		priority_queue<int> a;
		int t = n;
		while(n--)
		{
			int temp;
			cin>>temp;
			a.push(temp);
		}
		if(t<m)
		{
			cout<<"ERROR"<<endl;
			continue;
		}
		else
		{
			while(--m)
			{
				cout<<a.top()<<' ';
				a.pop();
			}
			cout<<a.top()<<endl;
		}
	}
}

抱歉!评论已关闭.