浙大pat 1029题解
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 Input
4 11 12 13 14
5 9 10 15 16 17
Sample Output
13
#include"iostream"
#include "algorithm"
#include "string"
#include "vector"
using namespace std;
long int first[1000000],second[1000000],result[2000000];
int main()
{
int n,m;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%ld",&first[i]);
}
scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%ld",&second[i]);
}
merge(first,first+n,second,second+m,result);
int pos = (n+m-1)/2;
cout<<result[pos]<<endl;
return 0;
}
浙大pat 1029题解的更多相关文章
- 浙大pat 1035题解
1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...
- 浙大pat 1025题解
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 浙大pat 1011题解
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
- 浙大PAT 7-06 题解
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 浙大 pat 1003 题解
1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 浙大 pat 1038 题解
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- 浙大 pat 1047题解
1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- 浙大pat 1054 题解
1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...
随机推荐
- java 文件下载支持中文名称
/** * 文件下载 * @param filePath 文件路径 * @param fileName 文件名称 */ public void download(String filePath,Str ...
- C++第二天
今天学会了反码和补码: 1.正数的反码是本身,负数的反码是高位不变,其余位取反(这里的数是指二进制数) 2.补码是反码加一得到的 对于数据类型分为基本类型:整型,浮点型,字符型和布尔值类型,还有飞基本 ...
- DOM小解
现在来说说DOM 文档对象模型DOM(Document Object Model)定义访问和处理html文档的标准方法.DOM将html文档呈现为带有元素 ,属性和文本的树结构(节点树) 先来看看 ...
- KMP 算法 学习 整理
我自己整理的KMP算法的PDF文件:http://pan.baidu.com/s/1o8yKIi2提取密码:8291 别的就不多说啥了,感谢来自海子 博客园的 资料--
- openstack私有云布署实践【9.3 主从controller单向同步glance-image目录】
采用Rysnc单向同步,而不用双方实时同步,原因是在历史的运行过程中,我们发现,有些镜像包太大,当在主用的glance将镜像保存时,并不是一时半会就把镜像保存好,当主用在保存时,备用节点又在实时同步那 ...
- JS 一些常用技巧
记录 JS 常用的技巧 1. 生成随机数 2. 解决浮点数问题 3. 无路可走时,看看是不是 事件 冒泡了...
- MongoDB1: 环境安装
1. 环境准备,不支持XP系统,需要在Windows7及以上和windows server 2008 系统上安装. 2. 下载安装包:http://www.mongodb.org/downloads, ...
- SAP HANA 创建属性视图
[Step By Step]SAP HANA创建属性视图(Attribute View) Demo Instruction: 从一张用户信息表中组合出相信地址. 1. 在modeler窗口中,找到相应 ...
- Excel 复制Sql查询结果错位
SELECT TOP 30000 REPLACE(REPLACE(T1.ReceiverName,CHAR(10),' '),CHAR(13),' ') AS ReceiverName, REPLAC ...
- 为 ngui TweenPosition 添加 pingpongone
//---------------------------------------------- // NGUI: Next-Gen UI kit // Copyright © 2011-2015 T ...