#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
/*Each element of the sequence is a positive integer not greater than 2^32 - 1 inclusive.
n为偶数时,如果把两个数相加再除以2,会溢出(大坑)
*/
int main()
{
int n, k;
while(~scanf("%d", &n)){
vector<int> v;
for(int i = 0; i < n; i ++)
{
scanf("%d", &k);
v.push_back(k);
}
sort(v.begin(), v.end());
double ans;
if(n % 2 == 0) ans = v[n/2-1] / 2.0 + v[n/2] / 2.0;//!!!
else ans = v[n/2];
printf("%.1f\n", ans);
}
return 0;
}
Sequence Median
最新推荐文章于 2022-02-07 20:54:28 发布