Description
长为L的升序序列S,S[L / 2]为其中位数。
给出两个等长升序序列S1和S2,求两序列合并并排序后的中位数。
Input
多组数据,每组第一行为n,表示两个等长升序序列的长度。
接下来n行为升序序列S1的元素,再接下来n行为升序序列S2的元素。
1 <= n <= 10 ^ 5,S内容为整数。
不超过5组数据。
Output
每组数据,输出合并并排序后的序列的中位数。
Sample Input
5
11
13
15
17
19
2
4
6
8
20
Sample Output
11
Thinking
sort来得很直接。
两个等长升序序列先后输入,看成一个数组也没事。
AC代码
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;
int a[200005];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(a,0,sizeof(a));
for(int i=0;i<2*n;i++)
{
cin>>a[i];
}
sort(a,a+2*n);
cout<<a[n-1]<<endl;
}
return 0;
}