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

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

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

#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]寻找大富翁

posted @ 2016-03-05 00:20  BoilTask  阅读(12)  评论(0编辑  收藏  举报