Day 5: Poisson Distribution II | 10 Days Of Statistics | HackerRank Solution

Hello coders, today we are going to solve Day 5: Poisson Distribution II HackerRank Solution which is a Part of 10 Days of Statistics Solution.

Day 5: Poisson Distribution II



In this challenge, we go further with Poisson distributions. 


The manager of a industrial plant is planning to buy a machine of either type A or type B. For each day’s operation:

  • The number of repairs, X, that machine A needs is a Poisson random variable with mean 0.88. The daily cost of operating A is CA = 160 + 40X2.
  • The number of repairs, Y, that machine B needs is a Poisson random variable with mean 1.55. The daily cost of operating B is CB = 128 + 40Y2.

Assume that the repairs take a negligible amount of time and the machines are maintained nightly to ensure that they operate like new at the start of each day. Find and print the expected daily cost for each machine.

Input Format

A single line comprised of 2 space-separated values denoting the respective means for A and B:

0.88 1.55

If you do not wish to read this information from stdin, you can hard-code it into your program.

Output Format

There are two lines of output. Your answers must be rounded to a scale of 3 decimal places (i.e., 1.234 format):

  1. On the first line, print the expected daily cost of machine A.
  2. On the second line, print the expected daily cost of machine B.

Solution – Poisson Distribution II


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    // given
    double l1 = 0.88, l2 = 1.55;
    double p1 = 160 + 40*(l1 + (l1*l1));
    double p2 = 128 + 40*(l2 + (l2*l2));
    printf("%0.3f\n%0.3f", p1, p2);
    return 0;

Disclaimer: The above Problem (Poisson Distribution II) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published.