PAT甲级1029
来源:互联网 发布:任易行期货软件 编辑:程序博客网 时间:2024/06/01 09:48
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
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<cstdio>#include<algorithm>#include<vector>#include<map>using namespace std;int main(){int N;scanf("%d", &N);vector<int> v; int t;for (int i = 0; i < N; i++){scanf("%d", &t);v.push_back(t);}scanf("%d", &N);for (int i = 0; i < N; i++){scanf("%d", &t);v.push_back(t);}sort(v.begin(), v.end());printf("%d", v[(v.size() - 1) >> 1]);return 0;}
- PAT(甲级)1029
- 浙大PAT甲级 1029
- PAT甲级1029
- 浙大PAT甲级-1029
- PAT甲级 1029
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- Spark常见问题解决办法
- maven私服nexus的配置说明
- elasticsearch中的数据类型
- OpenCV 图像遍历与颜色缩减
- 日期时间总结大全
- PAT甲级1029
- 【MCM-2017】2017年数学建模美赛题目原文及翻译-D(个人思路)
- java在mac上的安装路径
- (8421.BCD码)加权组合应用
- 求第n个数的斐波那数
- Android系统所有可申明的权限(中文)
- 【编程范式】【响应式编程】【本质】【到底是什么】
- 第七章 日志记录器
- study of hacking_linux(day1)