eolymp
bolt
Try our new interface for solving problems
Məsələlər

Probablisctic OR

Probablisctic OR

Everyone knows OR operation. Let us define new operation which we will call Probablistic OR. We will denote this operation as \textbf{#}. For given real number \textbf{p} (\textbf{0} ≤ \textbf{p} ≤ \textbf{1}) and two bits a and b: \begin{itemize} \item if \textbf{a} = \textbf{1} and \textbf{b} = \textbf{1}, then \textbf{#}(\textbf{a}, \textbf{b}) = \textbf{1}; \item if \textbf{a} = \textbf{0} and \textbf{b} = \textbf{0}, then \textbf{#}(\textbf{a}, \textbf{b}) = \textbf{0}; \item else \textbf{#}(\textbf{a}, \textbf{b}) = \textbf{0} with probability \textbf{p}, \textbf{#}(\textbf{a}, \textbf{b}) = \textbf{1} with probability \textbf{1-p}. \end{itemize} Now for two given non-negative integers \textbf{x} and \textbf{y} we can define bitwise Probablistic OR operation. The result of this operation is a number received by performing \textbf{#} operation for each pair of bits of \textbf{x} and \textbf{y} in same positions. For example, for \textbf{p} = \textbf{0.5}, \textbf{x} = \textbf{2}, and \textbf{y} = \textbf{4}, we will get \textbf{0}, \textbf{2}, \textbf{4} or \textbf{6} each with probability \textbf{0.25}. You will be given a list of non-negative integers. You have to implement a program which will calculate the expected value of the result of performing bitwise probablistic OR operation on all these numbers given some \textbf{p}. The numbers will be taken from left to right. \InputFile Input file starts with real number \textbf{p} (\textbf{0} ≤ \textbf{p} ≤ \textbf{1}) with exactly two digits after the decimal point. Integer \textbf{n} follows (\textbf{1} ≤ \textbf{n} ≤ \textbf{100}). Next line contains \textbf{n} numbers ai in the order they are taking part in the operation (\textbf{0} ≤ \textbf{a_i} ≤ \textbf{10^9}). \OutputFile Output the expected value of performing Probablistic OR operation on the given numbers for given \textbf{p}. Print the result with two digits after the decimal point.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
0.25 4
1 2 3 4
Çıxış verilənləri #1
5.11
Mənbə International Collegiate Programming Contest, Ukraine, Quarter-Final,May 19, 2011