Connection Status:
Competition Arena > Buoyancy
TCCC05 Semi 1 · 2005-01-10 · by dgoodman · Geometry, Math
Class Name: Buoyancy
Return Type: double
Method Name: waterLevel
Arg Types: (double, double, double, double, double)
Problem Statement

Problem Statement

An object can float only if it is less dense than water. A floating object displaces an amount of water equal to its weight. We are given an object (that may or may not float) and a container of water and we want to calculate the water level that will result when we place the object in the container. All weights are given in grams, all lengths are given in centimeters, and a cubic centimeter of water weighs one gram.

The container is a tall rectangular box (with no top) with horizontal dimensions wid x len. It is originally filled with water to a height of waterHt. The object is a rectangular solid that is 1 x 1 x objHt. The weight of the object is objWt. When placed in the water, the object remains upright whether it floats or rests on the bottom.

Create a class Buoyancy that contains a method waterLevel that is given wid, len, waterHt, objWt, and objHt and that returns the height of the water after the object has been placed in the container.

Notes

  • The returned value must be accurate to within a relative or absolute value of 1E-9

Constraints

  • wid and len will be between 1.2 and 10.0 inclusive.
  • waterHt, objWt, and objHt will be between 0.1 and 500.0 inclusive.
Examples
0)
2
2
100
150
80
Returns: 120.0

The object ends up on the bottom of the container, completely submerged. The final height of the water must be 120 since the total volume of the water and submerged object is 2*2*100 + 80 and that is equal to the new water level times the container's cross-section, 120*2*2.

1)
2
2
100
150
140
Returns: 133.33333333333334

This object also sinks, but does not get completely submerged. In the final situation, the total volume of the water and the part of the object that is submerged is 2*2*100 + 1*1*133.33 and that is equal to 2*2*133.3.

2)
2
2
100
10
160
Returns: 102.5

This object is very buoyant. It floats, with 10 units of its length submerged, displacing 10 grams of water. The total volume of the water and the submerged part of the object is then 2*2*100 + 10 and that is equal to 2*2*102.5.

3)
1.2
1.2
35
99
99
Returns: 103.75
4)
1.2
1.2
35
99
98
Returns: 103.05555555555556

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

Coding Area

Language: C++17 · define a public class Buoyancy with a public method double waterLevel(double wid, double len, double waterHt, double objWt, double objHt) · 17 test cases · 2 s / 256 MB per case

Submitting as anonymous