来源:互联网 发布:网络诈骗的典型案例 编辑:程序博客网 时间:2021/02/27 20:13

Crawling in process...Crawling failed
Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu


A median is described as the numeric value separating the higher half of a list, from the lower half. The median of a finite list of numbers can be found by arranging all the elements from lowest value to highest value and picking the middle one. If there is an even number of elements, the median is then defined to be the mean of the two middle values. Now, could you write a program to help to find the median?


There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.

The first line of each test is an integer 0 < n < 500 indicating the number of elements. The second line consists ofn numbers, the elements of the list, whose absolute values are smaller than 1,000,000.


For each test case, output the median, with 3 decimal digits.

Sample Input

310.041.0 1000.3 100.2 10.152.0 3.0 5.0 7.0 11.0

Sample Output




#include<stdio.h>#include<algorithm>using namespace std;int cmp(int a1,int b1){    return a1<b1;}double z[1000007];int main(){    int m;    while(scanf("%d",&m)!=EOF)    {        while(m--)        {            int n;            scanf("%d",&n);            for(int a=0;a<n;a++)            {                scanf("%lf",&z[a]);            }            sort(z,z+n,cmp);            if(n%2!=0)printf("%.3f\n",z[(n-1)/2]);            else            {                double count;                 count=z[n/2]+z[(n-2)/2];                printf("%.3f\n",count/2);            }        }    }    return 0;}