Problem Statement
We have a rectangular field with corners in points (0,0), (0,H), (W, H), and (W, 0). There is a carrot in every point with integer coordinates that lies inside or on the boundary of the field. Thus, there are exactly (H+1)*(W+1) carrots.
Someone is going to drop a bomb onto this field. The point where the bomb lands will be chosen uniformly at random from all points that lie inside or on the boundary of the field (including points with non-integer coordinates). When the bomb lands, it explodes and destroys all carrots that are within Euclidean distance R from the point of explosion.
You are given the
Definition
- Class:
- CarrotField
- Method:
- expectedValue
- Parameters:
- int, int, int
- Returns:
- double
- Method signature:
- double expectedValue(int H, int W, int R)
- (be sure your method is public)
Notes
- Your return value must have absolute or relative error smaller than 1e-7.
Constraints
- H, W, and R will be between 1 and 100,000, inclusive.
Examples
1
1
1
Returns: 3.141592653589793
The field is a 1x1 square with a carrot in each corner. Sometimes the bomb will destroy three of the four carrots. Other times (when it drops somewhere around the center of the square) it will destroy all four of them. Thus, the expected number of destroyed carrots must be somewhere between 3 and 4. The exact value happens to be pi = 3.14159...
20
22
25
Returns: 481.5403826061094
5
50
8
Returns: 85.87765067992017
100
100
999
Returns: 10201.0
Regardless of where the bomb drops, the radius of its explosion is so large that it will destroy all the carrots.
2386
12347
1234
Returns: 3571366.775318483
100000
100000
100000
Returns: 9.749440695616083E9
100000
100000
1
Returns: 3.141592653589793
100000
1
100000
Returns: 200002.00000230307
100000
1
1
Returns: 3.141592653589793
1
100000
100000
Returns: 200001.9999999999
1
100000
1
Returns: 3.141592653589793
1
1
100000
Returns: 4.0
1
1
1
Returns: 3.141592653589793
16502
22543
81604
Returns: 3.72043632E8
72271
79384
40288
Returns: 3.0240862059368196E9
29357
59920
90638
Returns: 1.759160717999997E9
77353
62112
88687
Returns: 4.80278155829228E9
45444
72705
19228
Returns: 8.432545671735239E8
31159
83790
16981
Returns: 6.343860495207442E8
39051
5844
34079
Returns: 2.244308590995291E8
46467
59620
14668
Returns: 5.23149998262318E8
65367
18944
36641
Returns: 9.847451307671864E8
82263
6058
72840
Returns: 4.918382806030287E8
67702
23556
39107
Returns: 1.2845767352058482E9
48506
43861
54623
Returns: 2.1229146420788226E9
34696
49688
44933
Returns: 1.6822357787600646E9
62146
5679
193
Returns: 115192.24637635618
32844
47503
43408
Returns: 1.5275858071933522E9
28282
5421
68908
Returns: 1.53350426E8
50659
48894
18741
Returns: 7.755828195484701E8
4130
10063
21819
Returns: 4.1574384E7
64249
77826
13809
Returns: 5.029503909756012E8
5445
94724
72452
Returns: 4.8726439485858256E8
1744
15046
62504
Returns: 2.6257015E7
59348
17579
29263
Returns: 7.583075276861935E8
87704
51654
1523
Returns: 7142827.237425231
71890
1395
87704
Returns: 1.00359836E8
77252
74307
5644
Returns: 9.383516794055557E7
38743
37660
29276
Returns: 1.1924857943455172E9
85144
57014
15216
Returns: 5.953384889110798E8
94045
52540
81233
Returns: 4.794886509479878E9
83136
62314
52931
Returns: 4.0079788799728165E9
72379
49663
66119
Returns: 3.5202195965507007E9
100
100
1
Returns: 3.141592653589793
example 0 before change to "100 100 1"
65000
80123
65000
Returns: 4.783724707602487E9
65000
80123
80123
Returns: 5.1613577637346525E9