浙大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 ...
随机推荐
- [DP之多重背包优化方法]
首先我们看一道有趣的题目 然后这道题很快想到是一个多重背包和无限背包混合体 那么我们就以这道题 来讨论一下多重背包的优化 首先我们看看朴素打法 memset(F,,]=; ;i<=N;i++) ...
- C#笔记(二)变量
C#把数据类型分为两种 ● 值类型 ● 引用类型 从概念上看:其区别是值类型直接存储其值,而引用类型存储对值的引用 这两种类型存储在内存的不同地方:值类型存储在堆栈中,而引用类型存储在托管堆上 如果变 ...
- gridview动态添加行(不用datatable实现)
GridViewRow newrow = , , DataControlRowType.Separator, DataControlRowState.Normal); TableCell[] tc=] ...
- 定位(position)
position :属性规定元素的定位类型 语法: position : static | absolute | fixed | relative JavaScript语法:object.style. ...
- URL中的#
作者:阮一峰 http://www.ruanyifeng.com/blog/2011/03/url_hash.html 一.#的涵义 #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如 ...
- Android 不能返回 parent Activity 的问题
使用 ActionBar,开启返回按钮: 在 Activity 的 onCreate 中添加下面代码 getSupportActionBar().setDisplayHomeAsUpEnabled(t ...
- CodeForces 707C Pythagorean Triples
数学,构造. 这题比较有意思,一开始没发现结论写了一个最坏复杂度为$O({10^9})$暴力居然能$AC$,正因为如此,我才发现了规律. 一开始是这么想的: 先假设$n$为直角边,设斜边长度为$c$, ...
- hdu1035
#include<stdio.h>#include<string.h>int step,n,m;int a[1010][1010];char map[11][11];void ...
- 1951: [Sdoi2010]古代猪文
1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2171 Solved: 904[Submit][Status] ...
- 递归——CPS(二)
给出一个计算树深度的函数: function treeDepth(curtree) { if(curtree == null) return 0; else { var leftDepth = tre ...