Recent Posts
Notice
No Rules Rules
통계학 (feat. 백준, 2108번) 본문
728x90
반응형
통계학
https://www.acmicpc.net/problem/2108
2108번: 통계학
첫째 줄에 수의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 단, N은 홀수이다. 그 다음 N개의 줄에는 정수들이 주어진다. 입력되는 정수의 절댓값은 4,000을 넘지 않는다.
www.acmicpc.net
반응형
// woohyeon.kim
// https://www.acmicpc.net/problem/2108
#include <iostream>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(NULL);
register int i, N, avg, count, ans, t = 0;
register short arr[500000] = { 0 };
map<int, int> tmpl;
cin >> N;
for (i = 0, avg = 0; i < N; ++i)
cin >> arr[i], avg += arr[i];
avg = round(avg / (double)N);
sort(arr, arr + N);
for (i = 0, count = 0; i < N; ++i)
++tmpl[arr[i]], count = max(count, tmpl[arr[i]]);
for (auto& item : tmpl) {
if (item.second == count) {
ans = item.first;
if (++t == 2)
break;
}
}
cout << avg << "\n" << arr[N / 2] << "\n" << ans << "\n" << arr[N - 1] - arr[0] << "\n";
return 0;
}
// *&)*@*
문제에서 주어진 최빈값은 여러 개 있을 때에는 최빈값 중 두 번째로 작은 값을 출력한다. 라는 조건이 있습니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
좌표 정렬하기 (feat. 백준, 11650번) (0) | 2022.08.02 |
---|---|
소트인사이드 (feat. 백준, 1427번) (0) | 2022.08.02 |
수 정렬하기 3 (feat. 백준 10989번) (0) | 2022.08.02 |
수 정렬하기 2 (feat. 백준, 2751번) (0) | 2022.08.02 |
수 정렬하기 (feat. 백준, 2750번) (0) | 2022.08.02 |
Comments