Age Sort UVA - 11462
题意:
给定若干居民的年龄(都是1~100之间的整数),把它们按照从小到大的顺序输出。
思路:
- 首先想到的是,把
数据排序之后输出,但是数据量有2e6,有点大,所以要想办法优化时间和空间上的开销。 - 内存限制太紧(甚至不能把它们全读入内存),因此无法使用快速排序方法,但整数范围很小,可以使用计数排序方法。
AC
#include <iostream>
#include <bits/stdc++.h>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
int main()
{
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
while(scanf("%d", &n)&&n){
int c[101]{},x;
For(i,1,n)scanf("%d", &x), c[x]++;
bool first = false;
For(i,1,100){
For(j,1,c[i]){
if(first)printf(" ");
printf("%d", i);
first = true;
}
}
puts("");
}
return 0;
}