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:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Minimum number of Bottles visible when a bottle can be enclosed inside another Bottle
- Maximum number of squares that can fit in a right angle isosceles triangle
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- Angle between a chord and a tangent when angle in the alternate segment is given
- Program to check if water tank overflows when n solid balls are dipped in the water tank
- Program to find amount of water in a given glass
- Find amount of water wasted after filling the tank
- Find if it's possible to rotate the page by an angle or not.
- Find other two sides of a right angle triangle
- 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
- 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
- Arc length from given Angle
- Angle between two Planes in 3D
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.