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

`sltest.testsequence.addStepBefore` 函数的用法如下: ```matlab sltest.testsequence.addStepBefore(blockPath, newStep, stepPath) ``` 其中,`blockPath` 是要添加测试步骤的 Simulink 模块路径,`newStep` 是要添加的测试步骤,`stepPath` 是要添加新步骤的位置。这个函数将在 `stepPath` 指定的位置之前添加新步骤。 例如,我们可以使用以下代码在 Simulink Test Sequence 中添加一个测试步骤: ```matlab % 打开 Simulink Test Sequence testSeq = sltest.testmanager.getTestSuites('Test Sequence'); open(testSeq); % 获取 Test Sequence 中的第一个测试用例 testCase = getTestCases(testSeq); testCase = testCase{1}; % 获取测试用例中的第一个测试序列 testSeqObj = getTestSequences(testCase); testSeqObj = testSeqObj{1}; % 获取测试序列中第一个测试步骤的路径 stepPath = getTestSteps(testSeqObj); stepPath = stepPath{1}; % 在第一个测试步骤之前添加一个新的测试步骤 newStep = sltest.testsequence.TestStep('Description', '测试步骤描述'); blockPath = '模块名称/子系统名称'; sltest.testsequence.addStepBefore(blockPath, newStep, stepPath); ``` 在这个例子中,我们首先打开 Simulink Test Sequence,并获取第一个测试用例和第一个测试序列。然后,我们获取第一个测试步骤的路径,并使用 `sltest.testsequence.TestStep` 创建一个新的测试步骤。最后,我们使用 `sltest.testsequence.addStepBefore` 将新步骤添加到第一个测试步骤之前。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值