Count of vessels completely filled after a given time | 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 ; Number of levels ; Number of seconds ; Function call
def FindNoOfFullVessels ( n , t ) : NEW_LINE INDENT Matrix = [ [ 0 for i in range ( n ) ] for j in range ( n ) ] NEW_LINE Matrix [ 0 ] [ 0 ] = t * 1.0 NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 ) : NEW_LINE INDENT exceededwater = Matrix [ i ] [ j ] - 1.0 NEW_LINE if ( exceededwater < 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT ans += 1 NEW_LINE if ( i + 1 < n ) : NEW_LINE INDENT Matrix [ i + 1 ] [ j ] += exceededwater / 2 NEW_LINE DEDENT if ( i + 1 < n and j + 1 < n ) : NEW_LINE INDENT Matrix [ i + 1 ] [ j + 1 ] += exceededwater / 2 NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT N = 3 NEW_LINE T = 4 NEW_LINE print ( FindNoOfFullVessels ( N , T ) ) NEW_LINE