1029. Median (25)
来源:互联网 发布:乌镇世界网络大会 编辑:程序博客网 时间:2024/06/08 05:00
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
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 (<=1000000) 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
For each test case you should output the median of the two given sequences in a line.
Sample Input4 11 12 13 145 9 10 15 16 17Sample Output
13
#include <iostream>#include <cstdio>#include <vector>#include <algorithm>using namespace std;int main(){int n1, n2;scanf("%d", &n1);vector<long int> seq1(n1);for(int i = 0; i < n1; ++i)scanf("%ld", &seq1[i]);scanf("%d", &n2);vector<long int> seq2(n2);for(int i = 0; i < n2; ++i)scanf("%ld", &seq2[i]);vector<long int> seq(n1+n2);merge(begin(seq1), end(seq1), begin(seq2), end(seq2), begin(seq));printf("%ld", seq[(n1+n2-1)/2]);return 0;}
- 1029. Median (25)
- 1029. Median (25)-PAT
- 【PAT】1029. Median (25)
- 1029. Median (25)
- 1029. Median (25)
- PAT 1029. Median (25)
- 1029. Median (25)
- PAT 1029. Median (25)
- PAT 1029. Median (25)
- 1029. Median (25)
- 1029. Median (25)
- 1029. Median (25)
- 1029. Median (25)
- 1029. Median (25)
- 1029. Median (25)
- 1029. Median (25)
- pat 1029. Median (25)
- 1029. Median (25)
- validate插件获取表单中某一项的验证情况
- XMLhttpRequest 请求 XML,JSON ,POJO 数据
- 获取已安装APP的信息
- Spring Test+JUnit完美组合
- 65条最常用正则表达式 你要的都在这里了
- 1029. Median (25)
- CodeVS1296 营业额统计
- UICollectionView - 调用delegate定义item大小后不调用collectionView:cellForItemAtIndexPath:函数的解决方法
- C#中对datatable的操作
- 关于带标签的注记如何获得其注记文本的问题
- latex中插入图片后不显示图片问题
- Adb connection Error:远程主机强迫关闭了一个现有的连接
- (总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解
- UML三个基本构造块之——九种图