Number of containers that can be filled in the given time | C ++ program for the above problem ; matrix of containers ; function to find the number of containers that will be filled in X seconds ; container on top level ; if container gets filled ; dividing the liquid equally in two halves ; driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double cont [ 1000 ] [ 1000 ] ; void num_of_containers ( int n , double x ) { int count = 0 ; cont [ 1 ] [ 1 ] = x ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { if ( cont [ i ] [ j ] >= ( double ) 1 ) { count ++ ; cont [ i + 1 ] [ j ] += ( cont [ i ] [ j ] - ( double ) 1 ) / ( double ) 2 ; cont [ i + 1 ] [ j + 1 ] += ( cont [ i ] [ j ] - ( double ) 1 ) / ( double ) 2 ; } } } cout << count ; } int main ( ) { int n = 3 ; double x = 5 ; num_of_containers ( n , x ) ; return 0 ; }