No.8 Sequence Median

原文:

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值