← 返回 uber 的题目列表Compute the CDF from a Normal Distribution PDF
类型:online_judge
Problem: Compute the CDF from a Normal Distribution PDF
You are given the PDF of a normal distribution:
[ f(x)=\frac{1}{\sigma\sqrt{2\pi}}\exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right) ]
Implement a program that, given (\mu), (\sigma), and multiple query points (x), outputs the CDF value for each (x):
[ F(x)=\int_{-\infty}^{x} f(t),dt ]
Input
Line 1: two real numbers (\mu) and (\sigma) ((\sigma>0))
Line 2: an integer (q), the number of queries
Next (q) lines: one real number (x) per line
Output
Print one CDF value per line.
Requirements
Do not call a built-in normal CDF (e.g., scipy.stats.norm.cdf).
You may use the error function erf (if allowed) or implement numerical integration/approximation.
Target absolute error within 1e-6.
Constraints (suggested)
(1 \le q \le 10^5)
(|\mu| \le 10^3), (0<\sigma \le 10^3)
(|x| \le 10^3)
Example
Input
0 1
3
0
1
-1
Output
0.5
0.841344746
0.158655254
Example
Input
0 1
3
0
1
-1
Output
0.5
0.841344746
0.158655254