Count of vessels completely filled after a given time | C ++ program to implement the above approach ; Function to find the number of completely filled vessels ; Store the vessels ; Assuming all water is present in the vessel at the first level ; Store the number of vessel that are completely full ; Traverse all the levels ; Number of vessel at each level is j ; Calculate the exceeded amount of water ; If current vessel has less than 1 unit of water then continue ; One more vessel is full ; If left bottom vessel present ; If right bottom vessel present ; Driver Code ; Number of levels ; Number of seconds ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int n , t ; int FindNoOfFullVessels ( int n , int t ) { double Matrix [ n ] [ n ] ; Matrix [ 0 ] [ 0 ] = t * 1.0 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { double exceededwater = Matrix [ i ] [ j ] - 1.0 ; if ( exceededwater < 0 ) continue ; ans ++ ; if ( i + 1 < n ) Matrix [ i + 1 ] [ j ] += exceededwater / 2 ; if ( i + 1 < n && j + 1 < n ) Matrix [ i + 1 ] [ j + 1 ] += exceededwater / 2 ; } } return ans ; } int main ( ) { int N = 3 ; int T = 4 ; cout << FindNoOfFullVessels ( N , T ) << endl ; return 0 ; }