Connection Status:
Competition Arena > Pillars
SRM 547 · 2011-11-22 · by sdya · Simple Math
Class Name: Pillars
Return Type: double
Method Name: getExpectedLength
Arg Types: (int, int, int)
Problem Statement

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.

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
0)
1
1
1
Returns: 1.0

The rope always has a length of 1.

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

2)
2
3
15
Returns: 6.737191281760445
3)
10
15
23
Returns: 12.988608956320535
4)
1000
100000
100000
Returns: 33381.38304701605
5)
1
99175
56445
Returns: 32073.471757648073

// precision is not too great, but seems ok

Submissions are judged against all 50 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Pillars with a public method double getExpectedLength(int w, int x, int y) · 50 test cases · 2 s / 256 MB per case

Submitting as anonymous