Suchan Is a Marine Boy!!
InterviewTime limit2sMemory limit512 MB
Given N practice records, compute the ratio of their arithmetic mean to the expected value of a value drawn uniformly from them, or print divide by zero.
- Level
Easy2 of 10
- Topics
- Math, Implementation, Array, Probability
- Solved
- No attempts yet
Problem
Pride of Busan! Hope of Dongnae! Suchan, who grew up dreaming of becoming a swimmer in the waters off Busan, has become a proud national team swimmer of our country (trivia: the word we use for our own country is written as a single compound word, 'urinara').
Suchan is browsing internet news to find interviews with experts about the 2020 Tokyo Summer Olympics. According to an expert who introduced himself as a professor, and according to research by a team at a famous European university, the probability that a swimmer can statistically show steady form at a competition similar to their practice is (the average of the practice records) / (the expected value when one of the practice records is chosen uniformly at random).
After reading this article, Suchan slapped his knee (!) and decided to calculate this probability with his own practice records. What is the probability that Suchan can show steady form?
Input
The first line gives N, the number of Suchan's practice records. (0 ≤ N ≤ 100)
The second line gives N practice records. If N is 0, nothing is given, and each practice record is a positive integer at most 100.
Output
Print the probability from the problem rounded to two decimal places (rounded at the third decimal place). If N is 0 or the denominator is 0, print "divide by zero".
Hint
The expected value E(X) is defined as 'the sum over all events of the gain from each event times the probability that the event occurs.' In other words, if the probability that a number x appears in the sequence is P(x) = (the number of times x appears) / (the length of the whole sequence), then the expected value is obtained by computing (x * P(x)) for every x that appears in the sequence and adding them all up.
\(E(X) = \sum_{i}{p_ix_i}\)
Consider example 1. The average is (5+10+10+15+20)/5 = 12, and the expected value is 5*(1/5) + 10*(2/5) + 15*(1/5) + 20*(1/5), which is also 12. Therefore the probability is 12/12 = 1.