PAT甲级练习1029. Median (25)
来源:互联网 发布:国盛证券交易软件 编辑:程序博客网 时间:2024/05/31 19:15
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 <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <string>#include <string.h>using namespace std;int main(){int n, sum=0;vector<long> v;for(int i=0; i<2; i++){scanf("%d", &n);sum += n;long l;for(int j=0; j<n; j++){scanf("%ld", &l);v.push_back(l);}}sort(v.begin(), v.end());printf("%ld", v[(sum-1)/2]);cin>>n;return 0;}
- PAT甲级练习1029. Median (25)
- 【PAT甲级】1029. Median (25)
- 1029. Median (25)PAT甲级
- PAT甲级1029. Median (25)
- PAT甲级 1029. Median (25)
- PAT甲级 1029. Median (25)
- PAT 甲级 1029. Median (25)
- PAT甲级 1029. Median (25)
- PAT(甲级)1029. Median (25)
- 1029. Median (25)-PAT甲级真题
- 1029. Median (25)-PAT甲级真题(two points)
- PAT甲级练习1025. PAT Ranking (25)
- 1029. Median (25)-PAT
- 【PAT】1029. Median (25)
- PAT 1029. Median (25)
- PAT 1029. Median (25)
- PAT 1029. Median (25)
- pat 1029. Median (25)
- Subresource Integrity
- JavaWeb中项目上有叹号
- 纪念
- sbrk() 函数是干什么的?
- MySQL常用函数之日期时间函数
- PAT甲级练习1029. Median (25)
- EDA软件_Cadence_Allegro 16.6元器件封装制作
- HPUOJ---2017寒假作业--专题-1/I-the Sum of Cube
- 注释镇楼
- Android中PendingIntent的简单使用
- 数据库——分类目录
- 【Android】安卓开发实战之使用layout_weight优化布局
- Map集合的四种遍历方式
- python复习笔记[4]——列表