Find the total area covered by two rectilinear rectangles in a 2D plane. 208MM

Find the total area covered by two rectilinear rectangles in a 2D plane.

Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.

Assume that 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;
    }
}//没考虑清楚,求面积不用判断符号,没有啥捷径目前发现分析各种情况,总结条件,编写代码有点像设计数字电路

  

时间: 2024-10-07 12:54:17

Find the total area covered by two rectilinear rectangles in a 2D plane. 208MM的相关文章

LeetCode:Rectangle Area - 矩形交叉部分的面积

1.题目名称 Rectangle Area(矩形交叉部分的面积) 2.题目地址 https://leetcode.com/problems/rectangle-area/ 3.题目内容 英文:Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown

[leedcode 223] Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. pu

Rectangle Area

https://leetcode.com/problems/rectangle-area/ Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is neve

leetcode_Rectangle Area _easy

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. 题目

leetcode Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. 看到

Rectangle Area - LeetCode

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. 思路

LeetCode223:Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Rectangle Area Assume that the total area is never beyond the maximum possible v

leetcode之Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. 这道

223. Rectangle Area

题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int