Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
135926 陈馨逸 双关键字排序 C++ 通过 100 478 MS 1036 KB 1226 2024-03-07 13:30:07

Tests(5/5):


#include<bits/stdc++.h> using namespace std; int n; struct shu { int a; int b; }shu[100001]; void bsort(int s,int t) { int i=s,j=t,mid=shu[(s+t)/2].b; while(i<=j) { while(shu[i].b<mid) i++; while(shu[j].b>mid) j--; if(i<=j) { swap(shu[i],shu[j]); i++; j--; } } if(s<j) bsort(s,j); if(i<t) bsort(i,t); return; } void fz(int i)//比较第二个数 { int j=i+1; for(;j<=n;j++) { if(shu[j].a != shu[i].a ) { break; } else continue; } bsort(i,j-1); } void xh(int n) { for(int i=1;i<=n;i++) { if(shu[i].a ==shu[i+1].a )//如果第一个数相等 { fz(i); } } } void asort(int s,int t) { int i=s,j=t,mid=shu[(s+t)/2].a; while(i<=j) { while(shu[i].a<mid) i++; while(shu[j].a>mid) j--; if(i<=j) { swap(shu[i],shu[j]); i++; j--; } } if(s<j) asort(s,j); if(i<t) asort(i,t); return; } int main() { cin>>n;//输入 for(int i=1;i<=n;i++) { cin>>shu[i].a>>shu[i].b; } //比较第一个数、排序 asort(1,n); xh(n);//循环比较第二个数 for(int i=1;i<=n;i++)//输出 { cout<<shu[i].a <<" "<<shu[i].b <<endl; } }


测评信息: