Median
来源:互联网 发布:网络诈骗的典型案例 编辑:程序博客网 时间:2024/04/24 23:26
Description
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?
Input
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.
Output
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
0.00055.1505.000
References
- http://en.wikipedia.org/wiki/Median
#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;}
- Median
- Median
- Median
- median
- Median
- Median
- Median
- median
- median
- Median
- Median Filter
- M Median
- Find Median
- ZOJ3612 Median
- Median Filter
- zju2011 Median
- 1029. Median
- PAT_1029: Median
- 实例详解C++友元
- Javabeans
- ios常用加密方法
- 整理一篇不错的关于软件加密的文章
- 在Ubuntu中安装Qt SDK时候遇到需要安装C++编译器的问题
- Median
- MSP430的精确延时
- C# Socket编程(1)基本的术语和概念
- iOS学习之sqlite的创建数据库,表,插入查看数据
- 向Berkeley DB插入大文件
- wince添加楷体字库
- hibernate不支持decode
- ACCESS转SQL注意事项
- 心跳服务器