Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
168019 B班 马淑龄 双关键字排序 C++ 解答错误 0 452 MS 1668 KB 1303 2024-08-19 21:50:57

Tests(0/5):


#include <bits/stdc++.h> using namespace std; int n,a[100001],b[100001],c[100001],d[100001],e[100001]; void quick_sort(int l,int r){ if (l>=r) return; int mid=rand()%(r-l+1)+l;//This value is random. int tb=0,tc=0,td=0;//b is smaller than a[mid],c is bigger than it,d is the same of it. for (int i=l;i<=r;i++){ if (a[i]<a[mid]) b[++tb]=a[i]; else if (a[i]>a[mid]) c[++tc]=a[i]; else d[++td]=a[i]; } for (int i=1;i<=tb;i++) a[l+i-1]=b[i]; for (int i=1;i<=td;i++) a[l+i-1+tb]=d[i]; for (int i=1;i<=tc;i++) a[l+i-1+tb+td]=c[i]; quick_sort(l,l+tb-1); quick_sort(l+tb+td,r); } void quick_sort1(int l,int r){ if (l>=r) return; int mid=rand()%(r-l+1)+l;//This value is random. int tb=0,tc=0,td=0;//b is smaller than a[mid],c is bigger than it,d is the same of it. for (int i=l;i<=r;i++){ if (e[i]<e[mid]) b[++tb]=e[i]; else if (e[i]>e[mid]) c[++tc]=e[i]; else d[++td]=e[i]; } for (int i=1;i<=tb;i++) e[l+i-1]=b[i]; for (int i=1;i<=td;i++) e[l+i-1+tb]=d[i]; for (int i=1;i<=tc;i++) e[l+i-1+tb+td]=c[i]; quick_sort1(l,l+tb-1); quick_sort1(l+tb+td,r); } int main(){ srand((int)time(0)); cin>>n; for (int i=1;i<=n;i++) cin>>a[i]>>e[i]; quick_sort(1,n); quick_sort1(1,n); for (int i=1;i<=n;i++) cout<<a[i]<<' '<<e[i]<<endl; return 0; }


测评信息: