Statistics

Problem Statement for "Pillars"

Problem Statement

On a horizontal line, there are two vertical pillars. The distance between their bottoms is w. The height of the first pillar is an integer, chosen uniformly at random in the range 1 through x, inclusive. The height of the second pillar is an integer, chosen uniformly at random in the range 1 through y, inclusive. The tops of both pillars will be connected by a straight piece of rope.

You are given the ints w, x, and y. Compute and return the expected length of the rope.

Definition

Class:
Pillars
Method:
getExpectedLength
Parameters:
int, int, int
Returns:
double
Method signature:
double getExpectedLength(int w, int x, int y)
(be sure your method is public)

Notes

  • Your return value must have a relative or an absolute error of less than 1e-9.
  • In this task, the expected rope length can be computed as the average rope length over all possible cases.

Constraints

  • w will be between 1 and 1000, inclusive.
  • x will be between 1 and 100,000, inclusive.
  • y will be between 1 and 100,000, inclusive.

Examples

  1. 1

    1

    1

    Returns: 1.0

    The rope always has a length of 1.

  2. 1

    5

    1

    Returns: 2.387132965131785

    There are 5 possible (equiprobable) cases in which the length of the rope is 1, sqrt(2), sqrt(5), sqrt(10) and sqrt(17). The correct answer is the arithmetic average of these 5 numbers.

  3. 2

    3

    15

    Returns: 6.737191281760445

  4. 10

    15

    23

    Returns: 12.988608956320535

  5. 1000

    100000

    100000

    Returns: 33381.38304701605

  6. 1

    99175

    56445

    Returns: 32073.471757648073

    // precision is not too great, but seems ok

  7. 741

    98283

    97708

    Returns: 32694.75809065241

  8. 772

    97431

    92415

    Returns: 31758.202091392817

  9. 987

    98228

    96988

    Returns: 32589.00970552789

  10. 890

    92714

    96949

    Returns: 31712.49684962615

  11. 884

    99111

    94672

    Returns: 32402.59188274667

  12. 741

    98835

    90385

    Returns: 31806.143660389673

  13. 729

    92658

    92366

    Returns: 30866.59996029441

  14. 746

    98939

    97438

    Returns: 32765.82263936255

  15. 808

    93569

    91507

    Returns: 30895.89432876109

  16. 849

    90577

    92202

    Returns: 30511.110044647055

  17. 963

    98047

    96381

    Returns: 32459.944104889895

  18. 917

    92247

    95421

    Returns: 31356.225216130268

  19. 976

    99917

    90443

    Returns: 32072.809658547325

  20. 706

    97598

    97448

    Returns: 32533.942518992055

  21. 755

    93628

    99334

    Returns: 32299.044059147163

  22. 1000

    94941

    97711

    Returns: 32184.135418201913

  23. 764

    91934

    99803

    Returns: 32193.015738418748

  24. 801

    95554

    90102

    Returns: 31080.165714689017

  25. 788

    92938

    99183

    Returns: 32183.11427643082

  26. 867

    94321

    90666

    Returns: 30917.68049883712

  27. 717

    98053

    97904

    Returns: 32686.415243153057

  28. 998

    97740

    90882

    Returns: 31646.771878422198

  29. 905

    92995

    99484

    Returns: 32261.73462507481

  30. 810

    96526

    93249

    Returns: 31700.36466772312

  31. 907

    97517

    96124

    Returns: 32321.451176681683

  32. 785

    96134

    96755

    Returns: 32181.491324592185

  33. 960

    90202

    97048

    Returns: 31415.623263082023

  34. 819

    97532

    94947

    Returns: 32137.140460237355

  35. 806

    97015

    98420

    Returns: 32612.35196213513

  36. 880

    93996

    94931

    Returns: 31530.840430364417

  37. 1

    100000

    100000

    Returns: 33333.33344872877

  38. 1000

    1

    100000

    Returns: 50028.496625165004

  39. 1

    1

    100000

    Returns: 49999.50006935564

  40. 100

    100000

    100000

    Returns: 33334.04348856876

  41. 1000

    100000

    10000

    Returns: 45374.871961122386

  42. 1000

    50000

    50000

    Returns: 16749.035733819004

  43. 10

    100000

    100000

    Returns: 33333.342735219885

  44. 44

    100000

    100000

    Returns: 33333.48670500142

  45. 1000

    99999

    99998

    Returns: 33380.88362205062

  46. 1000

    99999

    99999

    Returns: 33381.05009484778

  47. 998

    88888

    99999

    Returns: 31941.31591403921

  48. 1000

    99999

    100000

    Returns: 33381.216574215534

  49. 1000

    90000

    90000

    Returns: 30052.226096239192

  50. 1000

    92673

    92673

    Returns: 30942.03323926141


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: