Utkarsh and Faulty Rain Gauge

3.4

54 votes
Exception handling, Mathematics, Probability and Statistics, Easy
Problem

Utkarsh is going to Cherrapunji to visit his brother Saharsh. Cherrapunji faces one of largest rainfall in the country. So, Saharsh and Utkarsh decided to measure this rainfall by T Rain Gauges. They were going to measure it by taking the product of the readings of all the gauges. But, they found out that the gauges were not working properly and were producing random values. The brothers want to know what will be the expected result of the experiment.

The ith Rain Gauge has a least count of 1/Ri units. It has Ni divisions on its surface. Formally, it can give any reading from the set {0, 1/Ri , 2/Ri , ... ,Ni/Ri}. It gives a reading x with a probability proportional to x2.


Input Format:
The first line contains the integer T. T lines follow each containing 2 integers - Ni and Ri.


Output format:
Print the answer to the problem as real number exactly 4 decimal places. It is guaranteed that the answer is always less than 109.


Constraints:
1 ≤ T ≤ 103
1 ≤ Ni ≤ 103
1 ≤ Ri ≤ 103

NOTE:

  • A function p(x) is said to be proportional to x2 means p(x) = ax2 for some non negative a.

  • All the rain gauges produce values independently from each other.
  • Time Limit: 2
    Memory Limit: 256
    Source Limit:
    Explanation

    First gauge produces output

    1. 1/4 with probability = 0.2
    2. 2/4 with probability = 0.8

    Second gauge produces output

    1. 1/5 with probability = 0.2
    2. 2/5 with probability = 0.8

    The product is 1/4 * 1/5 ( = 0.05) with a probability of 0.2 * 0.2 ( = 0.04)
    The product is 1/4 * 2/5 ( = 0.1) with a probability of 0.2 * 0.8 ( = 0.16)
    The product is 2/4 * 1/5 ( = 0.1) with a probability of 0.8 * 0.2 ( = 0.16)
    The product is 2/4 * 2/5 ( = 0.2) with a probability of 0.8 * 0.8 ( = 0.64)

    Therefore the result is

    • 0.05 with probability = 0.04
    • 0.1 with probability = .016+0.16 = 0.32
    • 0.2 with probability = 0.64

    The Expected Result is therefore = 0.05 * 0.04 + 0.1 * 0.32 + 0.2 * 0.64 = 0.1620

    Editor Image

    ?