CT930

Monte Carlo: Estimate ¤Ç by Random Points

EasyAcceptance: 0.0%

In the Observatory of Prime City, the Astronomer uses the Monte Carlo method to estimate the value of ¤Ç. By scattering random points in a unit square and counting how many fall inside the inscribed quarter circle, the ratio approaches ¤Ç/4. "Generate N random points (x, y) in [0,1] x [0,1]," the Astronomer explains. "Count how many satisfy x^2 + y^2 <= 1. The ratio count/N approximates ¤Ç/4. For this problem, use a deterministic pseudo-random generator (LCG) so results are reproducible." Given N (number of points) and a seed, use a Linear Congruential Generator (LCG) with parameters m=2^31, a=1103515245, c=12345 to generate pairs (x, y) in [0,1). Count points inside the unit quarter circle and estimate ¤Ç as 4 * count / N. Output the estimate with 6 decimal places. Constraints: 1 <= N <= 10^7, 0 <= seed < 2^31 Input: 1000000 42 Output: 3.141592 Input: 100 1 Output: 3.080000

Constraints:

1 <= N <= 10^7, 0 <= seed < 2^31

Tags:

monte-carlo probability pi random math
Loading...
Test Cases:No test cases
No test cases available.
Monte Carlo: Estimate ¤Ç by Random Points - EASY Coding Problem | CodeTikki