国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

1029. Median (25)

2019-11-11 07:37:57
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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<cstdio>const int INF=0x7fffffff;const int maxn=1000010;int a[maxn],b[maxn];int main(){ int n1,n2; scanf("%d",&n1); for(int i=0;i<n1;i++){ scanf("%d",&a[i]); } scanf("%d",&n2); for(int i=0;i<n1;i++){ scanf("%d",&b[i]); } a[n1]=b[n2]=INF;//防止在掃描過(guò)程中,其中一個(gè)序列已掃描完,但還沒(méi)到中位數(shù)的情況 int pos=(n1+n2-1)/2; int i=0,j=0,count=0; while(count<pos){ if(a[i]<b[j]) i++; else j++; count++; } if(a[i]<b[j])
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 颍上县| 佳木斯市| 罗源县| 油尖旺区| 栖霞市| 永寿县| 成都市| 余庆县| 思茅市| 花垣县| 铅山县| 阜南县| 墨竹工卡县| 三台县| 文水县| 金堂县| 安国市| 彝良县| 明光市| 宕昌县| 桐庐县| 龙陵县| 庆城县| 怀柔区| 东至县| 栾川县| 安康市| 凉山| 右玉县| 临泉县| 五常市| 兴安盟| 荆门市| 耒阳市| 武穴市| 高邮市| 祥云县| 隆回县| 正蓝旗| 珠海市| 白银市|