PAT 甲级 1029 Median(25 分)

1029 Median(25 分)

Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, 10, 15, 16, 17 } is 15. The median of two sequences is defined to be the median of the nondecreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.

Given two increasing sequences of integers, you are asked to find their median.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (≤2×10​5​​) is the size of that sequence. Then N integers follow, separated by a space. It is guaranteed that all the integers are in the range of long int.

Output Specification:

For each test case you should output the median of the two given sequences in a line.

Sample Input:

4 11 12 13 14
5 9 10 15 16 17

Sample Output:

13
#include <iostream>
using namespace std;
int k[200005];
int main(){
    int n, m, temp, count = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%d", &k[i]);
    k[n + 1] = 0x7fffffff;
    cin >> m;
    int midpos = (n + m + 1) / 2, i = 1;
    for (int j = 1; j <= m; j++) {
        scanf("%d", &temp);
        while (k[i] < temp) {
            count++;
            if (count == midpos) cout << k[i];
            i++;
        }
        count++;
        if (count == midpos) cout << temp;
    }
    while (i <= n) {
        count++;
        if (count == midpos) cout << k[i];
        i++;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sen-Median趋势析方法是一种用于描述和析时间序列数据的统计工具。它通过将数据按照位置进行排序,确定数据的中间位置,将中间位置的数据作为时间序列的趋势模型。 Sen-Median趋势析方法主要为以下几个步骤:首先,将时间序列数据按照时间顺序进行排序。然后,计算出各个时间点数据的斜率值,即通过计算两个数据值的差值来衡量数据的变化趋势。接下来,找到数据斜率值的中位数,作为代表数据整体趋势的中间趋势。最后,根据中间趋势值来绘制趋势线,以展示数据的整体趋势。 Sen-Median趋势析方法具有以下几个特点:首先,它能够减轻极端值对趋势析结果的影响,使得趋势模型更加平滑和稳定。其次,这种方法不依赖于布假设,可以适用于不同类型的数据。第三,该方法计算简单,不需要对数据进行复杂的数学计算,比较易于理解和使用。 Sen-Median趋势析方法在实际应用中具有广泛的应用。例如,在金融领域,可以使用该方法来析股票价格的趋势,帮助投资者做出决策。在气象学中,可以利用该方法来研究气温变化的趋势,以预测天气情况。此外,在经济学、环境科学等领域,Sen-Median趋势析方法也有着广泛的应用。 总之,Sen-Median趋势析方法是一种用于揭示时间序列数据趋势的统计析工具,它的特点是稳定、简单易懂,广泛应用于各个领域。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值