原文:
Sequence Median
1000ms 65536K
描述:
Given a sequence of N nonnegative integers. Let's define the median of such sequence. If N is odd the median is the element with stands in the middle of the sequence after it is sorted. One may notice that in this case the median has position (N+1)/2 in sorted sequence if sequence elements are numbered starting with 1. If N is even then the median is the semi-sum of the two "middle" elements of sorted sequence. I.e. semi-sum of the elements in positions N/2 and (N/2)+1 of sorted sequence. But original sequence might be unsorted.
Your task is to write program to find the median of given sequence.
输入:
The first line of input contains the only integer number N - the length of the sequence. Sequence itself follows in subsequent lines, one number in a line. The length of the sequence lies in the range from 1 to 250000. Each element of the sequence is a positive integer not greater than 2^32 - 1 inclusive.
输出:
You should print the value of the median with exactly one digit after decimal point.
样例输入:
4 3 6 4 5
样例输出:
4.5
注释:
Huge input,scanf is recommended.
Source: Ural Collegiate Programming Contest 1998
译文:
数列中位数
描述:
给出一个含有N个正整数的数列,让我们来找到它的中位数,如果N是一个奇数,那么中位数就是该数列按大小排好序后,中间位置的那个元素的值。简而言之,就是N个元素,从第1个到第N个排好序,中位数为第(N+1)/2个元素。如果N为偶数,那么中位数就是两个中值的半和,即上述排好序的数列的第(N/2)个和第(N/2)+1个元素的半和。需要注意的是,起始数列可能是无序的。
你的任务是编写一个程序来找到给定数列的中位数。
输入:
第一行包含一个整数N,表示数列的元素个数(1 <= N <= 250000)
接下来的N行,每一行包含一个正整数,表示该数列的一个元素,每个元素大小不超过2^32
输出:
给出数列的中位数,要求用浮点数输出,精确的小数点后一位
样例输入:
4 3 6 4 5
样例输出:
4.5
注释:
大量数据的输入,推荐使用scanf函数
Source: Ural Collegiate Programming Contest 1998