快排,注意保留一位小数。
View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define maxn 250005
int n;
long long f[maxn], sum;
int main()
{
//freopen("t.txt", "r", stdin);
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%lld", &f[i]);
sort(f, f + n);
if (n & 1)
printf("%lld.0\n", f[n / 2]);
else
{
sum = 0;
sum += f[n / 2];
sum += f[n / 2 - 1];
if (sum & 1)
printf("%lld.5\n", sum / 2);
else
printf("%lld.0\n", sum / 2);
}
return 0;
}