Monte Carlo Integration
2026/3/9小于 1 分钟
Monte Carlo Integration
题面
在区间 [a,b] 上使用 Monte Carlo 方法估计 ∫_a^b f(x) dx:给定随机点的函数值 y_i=f(x_i),采用 (b-a) * (1/n) * Σ y_i 作为积分估计。
Implementation Requirements
- External libraries are not permitted
- The solve function signature must remain unchanged
- 结果写入
result;评测容差 abs/rel 1e-2
Examples
a = 0, b = 2, n=8, y = [0.0625, 0.25, 0.5625, 1.0, 1.5625, 2.25, 3.0625, 4.0]
result = 3.1875Constraints
- 1 ≤ n_samples ≤ 100,000,000
- -1000.0 ≤ a < b ≤ 1000.0;-10000.0 ≤ y ≤ 10000.0
- Performance: n_samples = 10,000,000