这道题,看很多人都是 分,看起来都使用了快排,但是 的时间复杂度 的规模过得去才怪。
再来看, 是 的规模,所以可以想到一种最新的排序方法——桶排!
AC代码
#include <bits/stdc++.h>
using namespace std;
int n, m, bu[2000010];
bool cmp(int x, int y) { return x < y; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
bu[x]++;
}
for (int i = 0; i < 1000; i++) {
for (int j = 1; j <= bu[i]; j++) {
cout << i << " ";
}
}
return 0;
}
结束!