Statistics

Problem Statement for "CarrotField"

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 ints H, W, and R. Return the expected number of destroyed carrots.

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

    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...

  2. 20

    22

    25

    Returns: 481.5403826061094

  3. 5

    50

    8

    Returns: 85.87765067992017

  4. 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.

  5. 2386

    12347

    1234

    Returns: 3571366.775318483

  6. 100000

    100000

    100000

    Returns: 9.749440695616083E9

  7. 100000

    100000

    1

    Returns: 3.141592653589793

  8. 100000

    1

    100000

    Returns: 200002.00000230307

  9. 100000

    1

    1

    Returns: 3.141592653589793

  10. 1

    100000

    100000

    Returns: 200001.9999999999

  11. 1

    100000

    1

    Returns: 3.141592653589793

  12. 1

    1

    100000

    Returns: 4.0

  13. 1

    1

    1

    Returns: 3.141592653589793

  14. 16502

    22543

    81604

    Returns: 3.72043632E8

  15. 72271

    79384

    40288

    Returns: 3.0240862059368196E9

  16. 29357

    59920

    90638

    Returns: 1.759160717999997E9

  17. 77353

    62112

    88687

    Returns: 4.80278155829228E9

  18. 45444

    72705

    19228

    Returns: 8.432545671735239E8

  19. 31159

    83790

    16981

    Returns: 6.343860495207442E8

  20. 39051

    5844

    34079

    Returns: 2.244308590995291E8

  21. 46467

    59620

    14668

    Returns: 5.23149998262318E8

  22. 65367

    18944

    36641

    Returns: 9.847451307671864E8

  23. 82263

    6058

    72840

    Returns: 4.918382806030287E8

  24. 67702

    23556

    39107

    Returns: 1.2845767352058482E9

  25. 48506

    43861

    54623

    Returns: 2.1229146420788226E9

  26. 34696

    49688

    44933

    Returns: 1.6822357787600646E9

  27. 62146

    5679

    193

    Returns: 115192.24637635618

  28. 32844

    47503

    43408

    Returns: 1.5275858071933522E9

  29. 28282

    5421

    68908

    Returns: 1.53350426E8

  30. 50659

    48894

    18741

    Returns: 7.755828195484701E8

  31. 4130

    10063

    21819

    Returns: 4.1574384E7

  32. 64249

    77826

    13809

    Returns: 5.029503909756012E8

  33. 5445

    94724

    72452

    Returns: 4.8726439485858256E8

  34. 1744

    15046

    62504

    Returns: 2.6257015E7

  35. 59348

    17579

    29263

    Returns: 7.583075276861935E8

  36. 87704

    51654

    1523

    Returns: 7142827.237425231

  37. 71890

    1395

    87704

    Returns: 1.00359836E8

  38. 77252

    74307

    5644

    Returns: 9.383516794055557E7

  39. 38743

    37660

    29276

    Returns: 1.1924857943455172E9

  40. 85144

    57014

    15216

    Returns: 5.953384889110798E8

  41. 94045

    52540

    81233

    Returns: 4.794886509479878E9

  42. 83136

    62314

    52931

    Returns: 4.0079788799728165E9

  43. 72379

    49663

    66119

    Returns: 3.5202195965507007E9

  44. 100

    100

    1

    Returns: 3.141592653589793

    example 0 before change to "100 100 1"

  45. 65000

    80123

    65000

    Returns: 4.783724707602487E9

  46. 65000

    80123

    80123

    Returns: 5.1613577637346525E9


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: