Given a water bottle with the shape of a rectangular prism whose base is a square of side x cm and height y cm, the task is to find the maximum angle at which we can tilt the bottle without spilling any water, when z cubic cm of water is poured into the bottle, and gradually tilt the bottle around one of the sides of the base.
Input: x = 2, y = 2, z = 4 Output: 45.00000 Explanation: This bottle has a cubic shape, and it is half-full. The water gets spilt when we tilt the bottle more than 45 degrees. Input: x = 12, y = 21, z = 10 Output: 89.78346
First of all, we need to know that the surface of the water is always parallel to the ground. So if the bottle tilts the water remain parallel to the ground.
Here we have 2 cases:-
- When the water is less than half of the total volume of the bottle, Then we consider the lower right triangle formed by water inside the bottle and with the help of tangent inverse calculate the required angle.
- When the water is greater than or equal to the total volume of the bottle, then we consider the upper right triangle formed by empty space inside the bottle. Now we can calculate the angle easily.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum number of Bottles visible when a bottle can be enclosed inside another Bottle
- Nth angle of a Polygon whose initial angle and per angle increment is given
- Maximum number of squares that can fit in a right angle isosceles triangle
- Program to check if water tank overflows when n solid balls are dipped in the water tank
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- Program to find amount of water in a given glass
- Angle between a chord and a tangent when angle in the alternate segment is given
- Find amount of water wasted after filling the tank
- Find other two sides of a right angle triangle
- Find if it's possible to rotate the page by an angle or not.
- Find other two sides and angles of a right angle triangle
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Program to find the Interior and Exterior Angle of a Regular Polygon
- Find the angle of Rotational Symmetry of an N-sided regular polygon
- Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Angle subtended by the chord when the angle subtended by another chord of same length is given
- Container with Most Water
- Measure one litre using two vessels and infinite water supply
- Minimum sprinklers required to water a rectangular park
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.