結果
| 問題 |
No.275 中央値を求めよ
|
| ユーザー |
|
| 提出日時 | 2020-07-07 16:22:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 713 bytes |
| コンパイル時間 | 772 ms |
| コンパイル使用メモリ | 79,524 KB |
| 最終ジャッジ日時 | 2025-01-11 16:41:30 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#include <iostream>
#include <iomanip>
#include <set>
using namespace std;
int main() {
multiset<int> ms;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
ms.insert(a);
}
int j = 0;
int size = ms.size();
float ans = 0;
for (auto iter = ms.cbegin(); iter != ms.cend(); ++iter) {
if (size % 2 == 0) {
if (j == size / 2 - 1) ans = *iter;
if (j == size / 2) ans = (ans + *iter) / 2.0f;
} else {
if (j == size / 2) {
ans = *iter;
break;
}
}
j++;
}
cout << fixed << setprecision(1) << ans << endl;
return 0;
}