提交记录 4345


用户 题目 状态 得分 用时 内存 语言 代码长度
Redpojoe 1001. 测测你的排序 Compile Error 0 0 ns 0 KB C++ 1.10 KB
提交时间 评测时间
2018-07-20 10:31:47 2020-07-31 22:52:18
//基数排序
#include<stdio.h>
const int P=65535;
const int M=1e8+5;
int n,A[M],temp[M],pos[M],neg[M],cnt[P+5],j,k;
void Input() {
	scanf("%d",&n);
	for(int i=0; i<n; i++)scanf("%d",&A[i]);
}
void Sort() {
	for(int i=0; i<n; i++) {
		if(A[i]>=0)pos[j++]=A[i];
		else neg[k++]=-A[i];
	}
	for(int i=0; i<j; i++)cnt[pos[i]&P]++;
	for(int i=1; i<=P; i++)cnt[i]+=cnt[i-1];
	for(int i=j-1; i>=0; i--)temp[--cnt[pos[i]&P]]=pos[i];
	for(int i=0; i<=P; i++)cnt[i]=0;
	for(int i=0; i<j; i++)cnt[(temp[i]>>16)&P]++;
	for(int i=1; i<=P; i++)cnt[i]+=cnt[i-1];
	for(int i=j-1; i>=0; i--)pos[--cnt[(temp[i]>>16)&P]]=temp[i];
	for(int i=0; i<=P; i++)cnt[i]=0;
	for(int i=0; i<k; i++)cnt[neg[i]&P]++;
	for(int i=1; i<=P; i++)cnt[i]+=cnt[i-1];
	for(int i=k-1; i>=0; i--)temp[--cnt[neg[i]&P]]=neg[i];
	for(int i=0; i<=P; i++)cnt[i]=0;
	for(int i=0; i<k; i++)cnt[(temp[i]>>16)&P]++;
	for(int i=1; i<=P; i++)cnt[i]+=cnt[i-1];
	for(int i=k-1; i>=0; i--)neg[--cnt[(temp[i]>>16)&P]]=temp[i];
}
void Output() {
	for(int i=k-1; i>=0; i--)printf("%d ",-neg[i]);
	for(int i=0; i<j; i++)printf("%d ",pos[i]);
}
int main() {
	Input();
	Sort();
	Output();
	return 0;
}

CompilationN/AN/ACompile ErrorScore: N/A


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-13 17:43:33 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠