记录编号 255315 评测结果 AAAAAAAAAA
题目名称 1537.多关键字基数排序 最终得分 100
用户昵称 KZNS 是否通过 通过
代码语言 C++ 运行时间 0.201 s
提交时间 2016-04-27 15:12:39 内存使用 6.07 MiB
显示代码纯文本
//KZNS
#include <fstream>
#include <cstdio>
#include <cstring>
using namespace std;
//
const int Nmax = 100003;
const int Mmax = 13;
//
int sm[10003];
int ls = 1, nw = 0;
int N, M;
int ed[2][Nmax];
int K[Mmax][Nmax];
//
inline void Bs(int b[], int v[], int e[],const int n) {
	memset(sm, 0, sizeof(sm));
	for (int i = 1; i <= n; i++)
		sm[v[i]]++;
	for (int i = 1; i < 10003; i++)
		sm[i] += sm[i-1];
	for (int i = n; i > 0; i--)
		e[sm[v[b[i]]]--] = b[i];
}
/*
inline void work(int t) {
	
}*/
//
int main() {
	//for (int t = 1; t <= 10; t++) {
		//char s[100], c[100];
		ifstream fin ("Bucketsort.in");
		ofstream fout ("Bucketsort.out");
		//sprintf(s, "Bucketsort%d.in", t);ifstream fin (s);
		//sprintf(c, "Bucketsort%d.ans", t);ofstream fout (c);
		fin >> N >> M;
		for (int j = 1; j <= M; j++)
			for (int i = 1; i <= N; i++)
				fin >> K[j][i];
		ls = 1, nw = 0;
		for (int i = 1; i <= N; i++)
			ed[ls][i] = i;
		for (int j = M; j >= 1; j--) {
			Bs(ed[ls], K[j], ed[nw], N);
			ls = nw;
			nw ^= 1;
		}
		for (int i = 1; i <= N; i++)
			fout << ed[ls][i] << ' ';
		//fin.close();
		//fout.close();
	//}
	return 0;
}
//UBWH