문제 링크입니다: www.acmicpc.net/problem/15921
15921번: 수찬은 마린보이야!!
기댓값 E(X)의 정의는 ‘각 사건이 벌어졌을 때의 이득과 그 사건이 벌어질 확률을 곱한 것을 전체 사건에 대해 합한 값’이다. 다시 말해, 어떤 수 x가 수열에 등장할 확률 P(x) = (x의 등장 횟수) /
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N; | |
cin >> N; | |
if (N == 0) | |
{ | |
cout << "divide by zero\n"; | |
return 0; | |
} | |
double sum = 0; | |
double expectedValue = 0; | |
for (int i = 0; i < N; i++) | |
{ | |
double record; | |
cin >> record; | |
sum += record; | |
expectedValue += record / N; | |
} | |
if ((int)expectedValue == 0) | |
{ | |
cout << "divide by zero\n"; | |
return 0; | |
} | |
double average = sum / N; | |
double result = average / expectedValue; | |
printf("%.2lf\n", result); | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 16017번 Telemarketer or not? (0) | 2021.03.23 |
---|---|
백준 15963번 CASIO (0) | 2021.03.23 |
백준 15873번 공백 없는 A+B (0) | 2021.03.22 |
백준 15726번 이칙연산 (0) | 2021.03.22 |
백준 15700번 타일 채우기 4 (0) | 2021.03.22 |