코딩놀이! 10 Days of Statistics(HackerRank)
Day 5 -1: Poisson Distribution I
13 번째 문제!
Objective Task Input Format The first line contains 's mean. The second line contains the value we want the probability for:
If you do not wish to read this information from stdin, you can hard-code it into your program. Output Format Print a single line denoting the answer, rounded to a scale of decimal places (i.e., format). |
문제해석!
1. 값이 랜덤인 변수 X 가 있다
2. X는 평균 2.5의 포아송 분포다.
3. X 가 5를 찾을 확률은?
여기서 잠깐!. 포아송 분포요?....
정의[편집]정해진 시간 안에 어떤 사건이 일어날 횟수에 대한 기댓값을 라고 했을 때, 그 사건이 회 일어날 확률은 다음과 같다. 여기서 는 자연상수이다. (출처: 위키, https://ko.wikipedia.org/wiki/%ED%91%B8%EC%95%84%EC%86%A1_%EB%B6%84%ED%8F%AC) |
어디다가 쓰냐고요?...
응용[편집]다음과 같은 확률적인 문제를 알아내기 위해 쓰이고 있다.
(출처: 위키, https://ko.wikipedia.org/wiki/%ED%91%B8%EC%95%84%EC%86%A1_%EB%B6%84%ED%8F%AC) |
이런다고 합니다 ㅋㅋ
난 잘 모르겟고 n!분의 람다(n승)* e(-람다승) 이라니깐 고대로 ㅋㅋ
계산식 포인트
Math.Pow(Math.E, -Expected_value) * Math.Pow(Expected_value,X) / Factorial(X)
Math.E(?응?) - 문제에서 e는 자연 상수를 나타내는데 값으로 나타내면 약 2.71828 이라고 수학에서 상수라고 한다
그럼 코드공개!
class Solution { private static readonly double EXPECTED_VALUE = 2.5; private static readonly int X = 5; static void Main(String[] args) { Console.WriteLine("{0:f3}", Math.Pow(Math.E, -EXPECTED_VALUE) * Math.Pow(EXPECTED_VALUE, X) / Factorial(X)); } static int Factorial(int n) { return (n == 0) ? 1 : n * Factorial(n - 1); } }
그럼이만! 혹시 설명이 부족하다면 댓글 달아주세용 ㅎ
(출처:https://www.hackerrank.com/challenges/s10-poisson-distribution-1/problem)