直接快排
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define maxn 10050
using namespace std;
int a[maxn];
struct Node{
int x;
int y;
bool operator <(const Node &other) const{
return x<other.x;
}
}node[maxn];
string s;
int main(){
int n,m=0,index;
int sum=0;
int t;
while(cin>>t){
for(int i=0;i<t;i++){
cin>>a[i];
}
sort(a,a+t);
cout<<a[t/2]<<endl;
}
return 0;
}
本文介绍了一种使用快速排序算法求解中位数的方法。通过直接快排,我们能够有效地对数组进行排序,并找到位于中间位置的元素,即中位数。此方法适用于需要快速找出一组数据中间值的场景。
476

被折叠的 条评论
为什么被折叠?



