Buoyancy
TCCC05 Semi 1 · 2005-01-10 · by dgoodman
Problem Statement
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.
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.
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 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.
1.2 1.2 35 99 99 Returns: 103.75
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.
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