1029. Median (25)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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题解的更多相关文章

  1. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  2. 浙大pat 1025题解

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  3. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  4. 浙大PAT 7-06 题解

    #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...

  5. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  6. 浙大 pat 1003 题解

    1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  7. 浙大 pat 1038 题解

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  8. 浙大 pat 1047题解

    1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  9. 浙大pat 1054 题解

    1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...

随机推荐

  1. CentOS部署yum本地源和共享

    约定yum本地源的机器IP为192.168.1.100,需要访问共享源的IP为192.168.1.101 关闭并禁止selinux和firewalld 创建本地源 1.上传centos7光盘镜像到指定 ...

  2. find指令参数

    1.name ~ 根目录 . 当前和子目录 name之后跟的是文件名 find . -name "[a-z]*[4-9].log" -print 2.perm perm后面跟的是权 ...

  3. javaee 规范技术

    J2EE的13种核心技术 一.JDBC(Java Database Connectivity) JDBC API为访问不同的数据库提供了一种统一的途径,象ODBC一样,JDBC对开发者屏蔽了一些细节问 ...

  4. Tiny6410之NAND FLASH驱动

    一.NAND FLASH的特点 S3C6410的NAND FLASH控制器有如下特点 1.自导入模式:复位后,引导代码被送入到8KB的STEPPINGSTONE中,引导代码移动完毕,引导代码将在STE ...

  5. table中td内容过长 省略号显示

    首先设置 css样式: table { table-layout: fixed;} HTML中的table代码: <tr> <th class="col-md-1" ...

  6. 【转】python删除文件里包含关键词的行

    import shutil with open('/path/to/file', 'r') as f: with open('/path/to/file.new', 'w') as g: for li ...

  7. Jersey+Spring+Maven环境搭建

    第一步:创建一个Maven工程.加入Jersey.Spring.Jersey+Spring的依赖包,以及内嵌的Tomcat7插件: pom.xml文件如图所示: <project xmlns=& ...

  8. Symfony没有安装依赖_PHP Fatal error: require(): Failed opening required

    $ php bin/console server:run PHP Warning: require(D:\home\workspace\pd\app/../vendor/autoload.php): ...

  9. 第一百一十六节,JavaScript,DOM操作样式

    JavaScript,DOM操作样式 一.操作样式 CSS作为(X)HTML的辅助,可以增强页面的显示效果.但不是每个浏览器都能支持最新的CSS能力.CSS的能力和DOM级别密切相关,所以我们有必要检 ...

  10. Chapter 19_0 位操作库

    位操作库是Lua5.2版本里添加的库,所有函数放在bit32 table里.(bit32只能针对32位整数运算) 在Lua5.3版本里,bit32库被废弃掉.不过可以使用一个外部兼容库,但是最好直接用 ...