[奇怪的东西] 松松鸡排

namespace Sort {
	const int BIT = 8;
	const int U = 256;
	int b[N], cnt[U];
	inline int get(int x, int d) {
		return (x >> (d * BIT)) & (U - 1);
	}
	inline void Fast_Sort(int *a, int n) {
		int *x = a, *y = b;
		for(int d = 0; d < 4; ++ d) {
			for(int i = 0; i < U; ++ i) cnt[i] = 0;
			for(int i = 1; i <= n; ++ i) ++ cnt[get(x[i], d)];
			for(int i = 1; i < U; ++ i) cnt[i] += cnt[i - 1];
			for(int i = n; i >= 1; -- i) y[cnt[get(x[i], d)] --] = x[i];
			swap(x, y);
		}
	}
} 
posted @ 2021-09-15 16:37  HN-wrp  阅读(37)  评论(0编辑  收藏  举报