全wa

P1168 中位数

_Glassy_Sky_ @ 2023-01-11 22:11:52

#include<bits/stdc++.h>
using namespace std;
int a[100001];
void qsort(int l, int r)
{
    int i, j, mid, p;
    i = l; j = r;
    mid = a[(l + r) / 2];
    do
    {
        while(a[i] < mid)
            i ++;
        while(a[j] > mid)
            j --;
        if(i <= j)
        {
            p = a[i];
            a[i] = a[j];
            a[j] = p;
            i ++;
            j --;
        }
    }while(i <= j);
    if(l < j)
        qsort(l, j);
    if(i < r)
        qsort(i, r);
}
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++)
        scanf("%d", &a[i]);
    qsort(1, n);
    printf("%d\n", a[1]);
    for(int i = 3; i <= n; i += 2)
        printf("%d\n", a[(i + 1) / 2]);
    return 0;
}

|