【杭电】[3785]寻找大富翁

文章字数:155

问题描述

问题分析

其实排序很简单就能写出来
不过既然放在队列专题
这个还是来写一下优先队列吧~

优先队列默认数据大的优先级高
所以这个可以很轻松地写出来

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<stdio.h>
#include<queue>
using namespace std;
int main() {
	int n,m;
	while(scanf("%d %d",&n,&m),n||m) {
		priority_queue<int>q;
		for(int i=0; i<n; i++) {
			int t;
			scanf("%d",&t);
			q.push(t);
		}
		for(int i=0; i<m; i++) {
			printf("%d",q.top());
			q.pop();
			if(i!=m-1)
				printf(" ");
			else
				printf("\n");
		}
	}
	return 0;
}

题目地址:【杭电】[3785]寻找大富翁

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...