結果

問題 No.275 中央値を求めよ
ユーザー ajiruajiru
提出日時 2020-02-05 04:53:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 378 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 80,528 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-21 18:54:45
合計ジャッジ時間 1,842 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	vector<double> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(a.begin(), a.end());
	double mid;
	if (n % 2 == 1) mid = a[n / 2];
	else mid = (a[n / 2 - 1] + a[n / 2]) / 2;
	cout << fixed << setprecision(10) << mid << endl;
	return 0;
}
0