本文主要是介绍寻找大富翁【浙江大学】★,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接
优先队列
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int arr[maxn];
int main(){int n,m,x;priority_queue<int, vector<int>, greater<int> > pq;while(cin>>n>>m){while(!pq.empty()){pq.pop();}for(int i=0;i<n;i++){cin>>x;if(pq.size() < m) pq.push(x);else if(pq.top() < x){pq.pop();pq.push(x);}}vector<int> ans;while(!pq.empty()){ans.push_back(pq.top());pq.pop();}reverse(ans.begin(), ans.end());for(int i=0;i<ans.size();i++){cout<<ans[i];if(i!=ans.size()-1) cout<<" ";else cout<<endl;}}return 0;
}
这篇关于寻找大富翁【浙江大学】★的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!