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. (89C51)定时器计时1s

    unsigned ; void initT1() { EA=; TH1=0xDC; TL1=0X00; TMOD=0x10; TR1=; ET1=; } { TH1=0xDC; TL1=0X00; c ...

  2. 【LeetCode】30. Substring with Concatenation of All Words

    You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...

  3. sort vector - leetcode 新用法

    179. Largest Number sort(num.begin(), num.end(), [](int a, int b){ return to_string(a)+to_string(b) ...

  4. Ajax.BeginForm无法调用 ajaxOptions的js函数

    使用ajax.beginForm无法调用ajaxOptions的js函数的原因,一般都是缺少以下2个JS文件: 1,Install-Package jQuery –version 1.10.22,In ...

  5. Chapter 2 Open Book——32

    I paused for a long moment, and then made the mistake of meeting his gaze. 我停顿了很长时间,然后错误的去对视了他的凝视 我停 ...

  6. table表头thead固定

    <html> <head> <meta charset="utf-8"/> <script type="text/javascr ...

  7. 如何使用Git上传代码到GitHub

    1.在Github上面创建Github仓库: 2.下载Github Shell到本地:https://desktop.github.com/ 3.打开Github Shell,输入以下命令生成秘钥来验 ...

  8. java 生成二维码

    package com.sun.erwei; import java.awt.Graphics2D;import java.awt.geom.AffineTransform;import java.a ...

  9. <验证码的产生>C语言---验证码的产生和验证

    无论在网页还是软件上登录时候都会遇到验证码的问题,不知道不懂其中奥秘的码友有没有兴趣一起来探讨一下. 其实并没有什么奥秘可言,就是产生随机数,然后让产生的随机数做为字符库(提前做好的数字字母字符串)的 ...

  10. tomcat7或8如何修改浏览器标题上的ICON小图标

    替换tomcat根目录/webapps/ROOT下的favicon.ico文件,之后重启了服务器,可是还是显示那只猫的图标. 如果不能显示,请清除浏览器的缓存