中位数问题3

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;
		}
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值