-
Notifications
You must be signed in to change notification settings - Fork 0
/
14609.fs
48 lines (38 loc) · 1.21 KB
/
14609.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
open System
// 14609
[<EntryPoint>]
let main _ =
let k = Console.ReadLine() |> int
let line = Console.ReadLine().Split ' ' |> Array.map float
let ab = Console.ReadLine().Split ' '
let (a, b, n) = (ab[0] |> float, ab[1] |> float, ab[2] |> int)
let actual =
let antd x =
let rec af i x =
match i with
| 0 -> line[i] * x / (float (k-i+1))
| _ -> x * (af (i-1) x) + line[i] * x / (float (k-i+1))
in af k x
in antd b - antd a
let good x = (abs (actual - x)) / actual < 0.00001
let func x =
let rec f i x =
match i with
| 0 -> line[i]
| _ -> x * (f (i-1) x) + line[i]
in f k x
let summed x =
let rec s i x =
let z = func (a + (b-a) * (float (i-1)) / (float n) + x) in
match i with
| 0 -> 0.
| _ -> s (i-1) x + z
in (b-a) * (s n x) / (float n)
let rec binsearch l r =
let t = (l+r)/2.
let s = summed t
if good s then t
else if s < actual then binsearch t r
else binsearch l t
printf "%f\n" (binsearch 0 ((b-a)/(float n)))
0