国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 竹山县| 万州区| 保定市| 张家口市| 开远市| 阿拉善左旗| 乐平市| 太谷县| 玛曲县| 仪征市| 霸州市| 突泉县| 清水河县| 慈溪市| 岱山县| 昌图县| 阿坝| 林芝县| 紫阳县| 洪洞县| 安化县| 客服| 泰兴市| 泉州市| 禄劝| 普兰县| 麦盖提县| 江源县| 长丰县| 鄢陵县| 定边县| 鄂温| 河西区| 峨眉山市| 类乌齐县| 甘泉县| 繁峙县| 厦门市| 东至县| 项城市| 崇州市|