반응형

코딩놀이! 10 Days of Statistics(HackerRank)

 Day 4 -3: Geometric Distribution I



11 번째 문제!

 Objective 

In this challenge, we learn about geometric distributions. Check out the Tutorial tab for learning materials!

Task 
The probability that a machine produces a defective product is . What is the probability that the  defect is found during the  inspection?

Input Format

The first line contains the respective space-separated numerator and denominator for the probability of a defect, and the second line contains the inspection we want the probability of being the first defect for:

1 3
5

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. 불량 확률 1/3(이공장망하겟네요)

2. 5번째에서 첫번쨰 불량 이 나올 확률을 구하라

계산식 포인트

Math.Pow(1-DEFECTIVE_PROBABILITY,FOUND_DEFECTIVE-1)*DEFECTIVE_PROBABILITY);

1. (정상-불량확률)pow(첫불량-1)*불량확률 이 답이겟네요

  *4번째까지 정상 확률과 마지막은 불량이나올확률 곱하기하는겁니당*


*이쯤 되니 이제 확률 문제는 계속 똑같은 계산식이라는게 느껴지네요 ㅎㅎ 처음에는 사실.....모든!!!확률을 다 공책에 썻어요 쓰면서 반복되는 작업 적기 적기 압축하기 하니깐 코드가 만들어지더라고요 ㅎㅎㅎ*

예를 들어 이번 문제같은 경우는 공책에 쓰면

AAAAA

AAAAB

AAAAC

.....

BBBBA

BBBBB

BBBBC

...

CCCCC


C만 불량 확률이죠 이렇게 공책에 다 써서 하는 무쉭한 방법이 있습니다.

하지만 컴퓨터라는건 사람이 할수있는일을 빠르게 아주 아주아주 빠르게 해결해주는 기계잖아요?ㅎㅎ

그러느 사람이할때 공통점을 뽑아서 간략하게 만들어서 기계에 입력해서 반복시키는 작업

만 할뿐,,,,,,

사실 지침에 한풀이였습니다 ㅋㅋㅋㅋ


그럼 코드공개!

class Solution {
    private static readonly double DEFECTIVE_PROBABILITY = (double)1/3;
    private static readonly int FOUND_DEFECTIVE = 5;
    static void Main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
        Console.Write(probability());
    }
    static string probability(){
        return string.Format("{0:0.000}",Math.Pow(1-DEFECTIVE_PROBABILITY,FOUND_DEFECTIVE-1)*DEFECTIVE_PROBABILITY);
    }
}






제출!!!


이번문제도 테스트 케이스 볼라면 5 hackos 바치라고해서 안봣습니다.ㅠ

드디어 한문제만 더 풀면 별하나 더주네요 ㅎㅎ 으쌰으쌰...는 내일..


4일차 4문제중 3개 Clear!




그럼이만! 혹시 설명이 부족하다면 댓글 달아주세용 ㅎ


(출처:https://www.hackerrank.com/challenges/s10-geometric-distribution-1/problem)

반응형

+ Recent posts