博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【PAT】1029. Median (25)
阅读量:6421 次
发布时间:2019-06-23

本文共 1232 字,大约阅读时间需要 4 分钟。

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 Input
4 11 12 13 145 9 10 15 16 17
Sample Output
13

分析:寻找中位数。一开始用sort来进行排序后找出中位数,但是这样会有两组数据超时。所以只能进行逐一比较。

代码:

 

#include
#include
#include
using namespace std;int main(){ int n; long t; int i; scanf("%d",&n); vector
vec1(n); for(i=0; i
vec2(n); for(i=0; i
result; for(i=0,j=0; i

 

 

转载地址:http://xplra.baihongyu.com/

你可能感兴趣的文章
im也去中心化?Startalk(星语)的去中心化设计之路
查看>>
BAT 经典算法笔试题 —— 磁盘多路归并排序
查看>>
一次完整的HTTP请求
查看>>
Nginx限制带宽
查看>>
All Web Application Attack Techniques
查看>>
归档日志ORA-19809: 超出了恢复文件数的限制
查看>>
精品德国软件 UltraShredder 文件粉碎机
查看>>
PANDAS 数据合并与重塑(join/merge篇)
查看>>
文件时间信息在测试中的应用
查看>>
Exception loading sessions from persistent storage (tomcat异常)
查看>>
直播疑难杂症排查(8)— 播放杂音、噪音、回声问题
查看>>
安装乌班图系统,并且演示有趣的linux命令,你还怕对linux无兴趣吗
查看>>
如何写gdb命令脚本
查看>>
Android ListView展示不同的布局
查看>>
iOS宏(自己使用,持续更新)
查看>>
手把手玩转win8开发系列课程(3)
查看>>
NGINX引入线程池 性能提升9倍
查看>>
《淘宝技术这十年》读书笔记 (四). 分布式时代和中间件
查看>>
linux下mongodb定时备份指定的集合
查看>>
oVirt JBAS server start failed, ajp proxy cann't server correct. ovirt-engine URL cann't open
查看>>