結果

問題 No.275 中央値を求めよ
ユーザー tancahn2380
提出日時 2017-09-16 05:24:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 678 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 89,832 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-25 00:39:10
合計ジャッジ時間 1,851 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	int n;
	int a;
	vector<double> v;
	cin >> n;
	double ans;
	for (int i = 0; i < n; i++) {
		cin >> a;
		v.emplace_back(a);
	}
	sort(v.begin(), v.end());
	if (n % 2 == 0) {
		ans = (v[n / 2] + v[n / 2 - 1]) / 2;
	}
	else {
		ans = v[n / 2];
	}
	cout << ans << endl;
}
0