POJ 2388 Who's in the Middle

水題…sort過了…但是如果題目的數據夠強的話可以考慮用Ultra Quick Sort的方法來找中位數,時間複雜度更低

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

#define MAXN 10050

int main(){
    int n;
    int a[MAXN]={0};
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    printf("%d\n",a[n/2]);
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章