Given the time required by a total of N+1 pipes where N pipes are used to fill the Cistern and a single pipe is used to empty the Cistern. The task is to Calculate the amount of time in which the Cistern will get filled if all the N+1 pipes are opened together.
Input: n = 2, pipe1 = 12 hours, pipe2 = 14 hours, emptypipe = 30 hours Output: 8 hours Input: n = 1, pipe1 = 12 hours emptypipe = 18 hours Output: 36 hours
- If a pipe1 can fill a cistern in ‘n’ hours, then in 1 hour, the pipe1 will able to fill ‘1/n’ Cistern.
- Similarly If a pipe2 can fill a cistern in ‘m’ hours, then in one hour, the pipe2 will able to fill ‘1/m’ Cistern.
- So on…. for other pipes.
So, total work done in filling a Cistern by N pipes in 1 hours is
1/n + 1/m + 1/p…… + 1/z
Where n, m, p ….., z are the number of hours taken by each pipes respectively.
The result of the above expression will be the part of work done by all pipes together in 1 hours, let’s say a / b.
To calculate the time taken to fill the cistern will be b / a.
Consider an example of two pipes:
Time taken by 1st pipe to fill the cistern = 12 hours
Time taken by 2nd pipe to fill the cistern = 14 hours
Time taken by 3rd pipe to empty the cistern = 30 hours
Work done by 1st pipe in 1 hour = 1/12
Work done by 2nd pipe in 1 hour = 1/14
Work done by 3nd pipe in 1 hour = – (1/30) as it empty the pipe.
So, total work done by all the pipes in 1 hour is
=> ( 1 / 12 + 1/ 14 ) – (1 / 30)
=> ((7 + 6 ) / (84)) – (1 / 30)
=> ((13) / (84)) – (1 / 30)
=> 51 / 420
So, to Fill the cistern time required will be 420 / 51 i.e 8 hours Approx.
Below is the implementation of above approach:
- Minimum number of integers required to fill the NxM grid
- Minimum number of bottles required to fill K glasses
- Minimum number of square tiles required to fill the rectangular floor
- Minimum time required to complete a work by N persons together
- Fill array with 1's using minimum iterations of filling neighbors
- Changing One Clock Time to Other Time in Minimum Number of Operations
- Minimum time to reach a point with +t and -t moves at time t
- Time required to meet in equilateral triangle
- Minimum Players required to win the game
- Minimum number of operations required to reduce N to 1
- Minimum number of palindromes required to express N as a sum | Set 2
- Minimum number of palindromes required to express N as a sum | Set 1
- Minimum inversions required so that no two adjacent elements are same
- Minimum operations required to change the array such that |arr[i] - M| <= 1
- Minimum number of given operation required to convert n to m
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.