#449easySimulation
Monte Carlo Pi Estimation
Time Limit: 5sMemory: 256MB
Problem
Estimate using Monte Carlo simulation. Generate random points uniformly in the unit square and count how many fall inside the unit quarter-circle ().
Use a Linear Congruential Generator (LCG) for deterministic pseudorandom numbers:
Convert to uniform : . For each point, draw two consecutive values to get coordinates .
Input Format
Two space-separated integers: N seed
Output Format
The estimate of , to 4 decimal places.
Examples
Example 1
Input(Two space-separated integers: N seed)
1000 42
Output
3.1240
With 1000 points and seed=42, the LCG produces a pi estimate near 3.124.
Example 2
Input(Two space-separated integers: N seed)
10000 123
Output
3.1376
With 10000 points, the estimate gets closer to the true value.
Constraints
- •100 ≤ N ≤ 1000000
- •0 ≤ seed ≤ 10^9
- •Output to 4 decimal places
Loading interactive editor…