POJ 2388 Who's in the Middle

题目链接:POJ 2388【Who's in the Middle】



思路

       求中位数,排序输出中间的数字。


代码

#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
const int N = 1e5 + 10;

int a[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin>> a[i];
  }
  sort(a + 1, a + 1 + n);
  cout << a[(n + 1) >> 1] << endl;

  return 0;
}
posted @ 2024-07-26 15:48  薛定谔的AC  阅读(3)  评论(0编辑  收藏  举报