Find the total area covered by and rectilinear rectangles in a 2D plane.
Each rectangle was defined by its bottom left corner and top right corner as shown in the figure.
Assume the total area is never beyond the maximum possible value of int.
public class Solution {public static void main (String args[]) {Solution A = new solution (); int c =a.computearea ( -2,-2,2,2,3 , 3,4,4); System.out.println (c);} public int Computearea (int A, int B, int C, int D, int E, int F, int G, int H) { int sqr = 0; Sqr = (c-a>0? (c-a):(a-c)) * (d-b>0? ( D-b):(b-d) + (h>f?) H-F:F-H) * (g>e? G-E:E-G); int result; result = Sqr-area (min (c,g), Min (d,h), Max (a,e), Max (b,f)); Return (e>c| | f>d| | b>h| | A>G)? Sqr:result; } public int area (int A, int B, int C, int D) { int sqr; Sqr = (c-a>0? (c-a):(a-c)) * (d-b>0? ( D-b):(b-d)); return SQR; } public int min (int a,int b) { int c; c = a>b? b:a; return c; } public int max (int a,int b) { int c; c = a>b? A:B; return c; }}
Did not consider clearly, the area does not have to judge the symbol, there is no shortcut now found
Analyze various situations, summarize conditions, write code
Kind of like designing digital circuits.
Find The total area covered by and rectilinear rectangles in a 2D plane. 208MM