Description
给你一个数字N,再给你N个数字,N是偶数
整个数列的中位数被认为是排序后第N/2个位置上的数字
问你:
如果去掉并且只去掉第1数字后,新数列中的中位数是多少?
如果去掉并且只去掉第2数字后,新数列中的中位数是多少?
如果去掉并且只去掉第3数字后,新数列中的中位数是多少?
如果去掉并且只去掉第n数字后,新数列中的中位数是多少?
Format
Input
一行给出数字N.
接下来一行N个数字Xi,代表这个数列
2≤N≤200000
N是一个偶数
1≤Xi≤10^9
Output
如题
Samples
输入数据 1
4
2 4 4 3
Copy
输出数据 1
4
3
3
4
纯纯思维题
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<iomanip>
#include<set>
#include<queue>
#include<stack>
#include<map>
using namespace std;
int n, a[200000], b[200000];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
b[i] = a[i];
}
sort(a + 1, a + 1 + n);
int a1 = a[n / 2], a2 = a[n / 2 + 1];
for (int i = 1; i <= n; i++)
{
if (b[i] <= a1)
{
cout << a2 << endl;
}
else if (b[i] >= a2)
{
cout << a1 << endl;
}
}
}