Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 대수경
- 다리로봇
- 전국 대학생 수학 경시대회
- 텔레스코픽로봇
- 최적제어
- baekjoon
- mathematics for computer science
- 수학
- 큐
- HJB방정식
- LeggedRobot
- 로보틱스
- baekjoon problem solving
- 집합과 맵
- 정렬
- MIT opencourse
- 백준
- 실버 4
- 실버 5
- BOJ
- lqr
- std::sort
- 구현
- 6.042j
- C++
- 문자열
- 논문리뷰
- mit
- 자료구조
- 로봇공학
Archives
- Today
- Total
서두르지 말고 쉬지 말자
백준 2108번 통계학(C++) 본문
문제 해결 방안 : 문제가 요구하는 각 부분을 순서대로 구현했다. 기존에 알던 이론은 계수 정렬이 사용되었고 반올림 관련해서는 구글링을 해서 해결했다.
문제 해결 소감 : 추가로 알게된 중요한 방법이나 깨달음은 없었다. 그래도 이제 이 정도 규모의 문제를 혼자 힘으로 해결 가능하게 된 것이 뿌듯하다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
int N;
int num;
double total = 0;
int arr[8001] = {};
int main(void)
{
std::cin >> N;
std::vector<int> v(N);
for (auto &c : v)
{
std::cin >> num;
c = num;
}
// 산술평균
for (auto c : v)
{
total += c;
}
double dec = total / N;
int plus = 0;
if (dec - std::trunc(dec) >= 0.5 || dec - std::trunc(dec) <= (-0.5))
{
if (dec >= 0)
plus += 1;
else
plus -= 1;
}
std::cout << trunc(dec) + plus << '\n';
// 중앙값
std::sort(v.begin(), v.end());
std::cout << v[N / 2] << '\n'; // 맞음
// 최빈값
for (auto c : v)
{
arr[c + 4000] += 1;
}
int maxVal = *(std::max_element(arr, arr + 8001));
std::vector<int> cand;
for (int i = 0; i < 8001; ++i)
{
if (arr[i] == maxVal)
{
cand.push_back(i - 4000);
}
}
std::sort(cand.begin(), cand.end());
if (cand.size() < 2)
{
std::cout << cand[0] << '\n';
}
else
{
std::cout << cand[1] << '\n';
}
// 범위
auto max = std::max_element(v.begin(), v.end());
auto min = std::min_element(v.begin(), v.end());
std::cout << *max - *min; // 맞음
}반응형
'코딩 공부 > Baekjoon Problem Solving' 카테고리의 다른 글
| 백준 2609번 최대공약수와 최소공배수(C++) (0) | 2025.02.12 |
|---|---|
| 백준 2775번 부녀회장이 될테야(C++) (0) | 2025.02.10 |
| 백준 10989번 수 정렬하기 3(C++) (3) | 2025.01.14 |
| 백준 2751번 수 정렬하기 2(C++) (1) | 2025.01.14 |
| 백준 1181번 단어 정렬[C++] (2) | 2025.01.13 |
