记录编号 505351 评测结果 AAAAAAAAAA
题目名称 多关键字基数排序 最终得分 100
用户昵称 GravatarKZNS 是否通过 通过
代码语言 C++ 运行时间 0.225 s
提交时间 2018-08-13 13:34:53 内存使用 5.75 MiB
显示代码纯文本
#include <cstdio>
#include <cstring>
using namespace std;
#define Nmax 100003
#define Mmax 13
int N, M;
int v[Mmax][Nmax];
int buk[Nmax];
int ls[2][Nmax];
inline void bucketsort(int b[], int h[], int e[], int n) {
    memset(buk, 0, sizeof(buk));
    for (int i = 1; i <= n; i++)
        buk[h[b[i]]]++;
    for (int i = 1; i <= 1000; i++)
        buk[i] += buk[i-1];
    for (int i = n; i >= 1; i--)
        e[buk[h[b[i]]]--] = b[i];
}
int main() {
    freopen("Bucketsort.in", "r", stdin);
    freopen("Bucketsort.out", "w", stdout);
    scanf("%d %d", &N, &M);
    for (int j = 1; j <= M; j++)
        for (int i = 1; i <= N; i++)
            scanf("%d", &v[j][i]);
    int lt = 0, nw = 1;
    for (int i = 1; i <= N; i++)
        ls[lt][i] = i;
    for (int j = M; j >= 1; j--) {
        bucketsort(ls[lt], v[j], ls[nw], N);
        lt = nw;
        nw ^= 1;
    }
    for (int i = 1; i <= N; i++)
        printf("%d ", ls[lt][i]);
    return 0;
}