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

首頁 > 學院 > 開發設計 > 正文

PAT A1029. Median (25)

2019-11-08 02:11:33
字體:
來源:轉載
供稿:網友

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 145 9 10 15 16 17Sample Output
13
#include <cstdio>#include <algorithm>#include <cstring>#define Max 1000010const int MAX = 10000000;using namespace std;int main(){	int s1[Max],s2[Max];	int n,m,k=0;	scanf("%d",&n);	for(int i=0;i<n;i++) 	{		scanf("%d",&s1[i]);	}	scanf("%d",&m);	for(int i=0;i<m;i++)	{		scanf("%d",&s2[i]);	}	s1[n]=s2[m]=MAX;	int f=(n+m-1)/2;	int i=0,j=0;	while(k<f)	{		if(s1[i]<s2[j]) i++;		else j++;		k++;	}	if(s1[i]<s2[j]) PRintf("%d",s1[i]);	else printf("%d",s2[j]);	system("pause");	return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苏尼特右旗| 平远县| 凤冈县| 图片| 岱山县| 镇赉县| 安塞县| 封开县| 海盐县| 陆河县| 花莲市| 喀什市| 长岭县| 赤壁市| 陕西省| 从江县| 桃园市| 水富县| 鹤山市| 苍南县| 广安市| 博爱县| 门头沟区| 大埔区| 淮阳县| 台山市| 贵定县| 丰台区| 兰西县| 犍为县| 若羌县| 镇巴县| 密云县| 海淀区| 武定县| 满洲里市| 资源县| 合肥市| 奉新县| 长宁县| 长沙县|