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. trove design翻译

    trove的设计 高水平的描述 trove的目的是支持单租户数据库,在一个nova的实例中.没有限制nova是如何配置的,因为trove与其他OpenStack组件纯粹通过API. Trove-api ...

  2. 关于 Unchecked cast from Iterator to Iterator String 提示

    遇到个这个提示:Unchecked cast from Iterator to Iterator String Iterator<String> keys = data.keys(); 修 ...

  3. excel 导入 与 导出

    Excel导入 public ActionResult Excel(HttpPostedFileBase file)        {            HttpPostedFileBase fi ...

  4. Python_Selenium2Library源码分析

    I. Introduction Selenium2Library是robot framework中主流的测试网页功能的库, 它的本质是对webdriver的二次封装, 以适应robot框架. 百度上一 ...

  5. [SOJ] shortest path in unweighted graph

    Description 输入一个无向图,指定一个顶点s开始bfs遍历,求出s到图中每个点的最短距离. 如果不存在s到t的路径,则记s到t的距离为-1.   Input 输入的第一行包含两个整数n和m, ...

  6. ONE WIRE

    以温度温度传感器为例 由三根线,分别为电源,信号,地线 使用GPIO口对信号线进行读操作 //初始化GPIO PC0端口void dht11_init(){ GPIO_InitTypeDef GPIO ...

  7. 【Time系列二】自动关机脚本

    今天在弄那个自动关机脚本的时候,遇到最大的麻烦就是怎么像电脑一样显示关机时间,看 了其他大神的博客,明白了原来用的是我没学过的datetime模块和time.strptime模块 ! ! ! 接下来, ...

  8. C#中的DataSet添加DataTable问题

    最近在使用DataTable来给前台控件绑定数据,开始时查了网上的一些给DataSet添加DataTable时需要注意的地方,一般都要添加表名并且使用DataTable.Copy()方法,否则会报错, ...

  9. iis无法加载样式

  10. 批处理改hosts

    @echo off color 0F @attrib -r "%windir%\system32\drivers\etc\hosts" @echo ######测试配置 beg & ...