题目描述 :
给定N(N≤500,000)和N个整数(较有序),将其排序后输出。
输入描述 Input Description
N和N个整数
输出描述 Output Description
N个整数(升序)
样例输入 Sample Input
5
12 11 10 8 9
样例输出 Sample Output
8 9 10 11 12
数据范围及提示 Data Size & Hint
对于33%的数据 N≤10000
对于另外33%的数据 N≤100,000 0≤每个数≤1000
对于100%的数据 N≤500,000 0≤每个数≤2*10^9
这道题可以用堆排做
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<queue>
using namespace std;
priority_queue <int,vector<int>,greater<int> > a;
int main() {
int n,k,l,js=0;
cin>>n;
for(int i=1; i<=n; i++) {
cin>>k;
a.push(k);
}
for(int i=1; i<=n; i++) {
cout<<a.top()<<" ";
a.pop();
}
return 0;
}
是不是很简单
使用堆排序解决整数排序问题
本文介绍了一种利用优先队列实现堆排序的方法来解决大规模整数序列的排序问题。通过C++代码示例展示了如何输入一组整数,并使用优先队列按升序输出这些整数。
31万+

被折叠的 条评论
为什么被折叠?



