Total number of unit cells covered by all given Rectangles | Python3 program to find the number of cells enclosed by the given rectangles ; Update the coordinates lying within the rectangle ; Update arr [ i ] [ j ] for all ( i , j ) lying within the rectangle ; Function to return the total area covered by rectangles ; Stores the number of cells ; arr [ i ] ] [ [ j ] == 1 means that grid is filled by some rectangle ; Driver code ; ( A [ i ] [ 0 ] , A [ i ] [ 1 ] ) denotes the coordinate of the bottom left of the rectangle ( A [ i ] [ 2 ] , A [ i ] [ 3 ] ) denotes the coordinate of upper right of the rectangle ; Update the coordinates that lie within the rectangle
MAX = 1001 NEW_LINE arr = [ [ False for i in range ( MAX ) ] for j in range ( MAX ) ] NEW_LINE def updateArray ( x1 , y1 , x2 , y2 ) : NEW_LINE INDENT for i in range ( x1 , x2 ) : NEW_LINE INDENT for j in range ( y1 , y2 ) : NEW_LINE INDENT arr [ i ] [ j ] = True NEW_LINE DEDENT DEDENT DEDENT def findAreaCovered ( ) : NEW_LINE INDENT area = 0 NEW_LINE for i in range ( MAX ) : NEW_LINE INDENT for j in range ( MAX ) : NEW_LINE INDENT if arr [ i ] [ j ] : NEW_LINE INDENT area += 1 NEW_LINE DEDENT DEDENT DEDENT return area NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 3 NEW_LINE A = [ [ 1 , 3 , 4 , 5 ] , [ 3 , 1 , 7 , 4 ] , [ 5 , 3 , 8 , 6 ] ] ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT updateArray ( A [ i ] [ 0 ] , A [ i ] [ 1 ] , A [ i ] [ 2 ] , A [ i ] [ 3 ] ) ; NEW_LINE DEDENT area = findAreaCovered ( ) ; NEW_LINE print ( area ) NEW_LINE DEDENT