zoukankan      html  css  js  c++  java
  • 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.

    Rectangle Area

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

      

  • 相关阅读:
    集群技术
    Docker Swarm(一)
    服务器集群
    生产环境swarm集群规划和管理
    集群的分类
    Arcengine C#开发源码
    BIOS设置中开启cpu睿频功能
    aida64怎么用?aida64最详细的使用教程
    SQL Server2019最大并行度
    IIS 之 在IIS7、IIS7.5中应用程序池最优配置方案
  • 原文地址:https://www.cnblogs.com/puck/p/4562088.html
Copyright © 2011-2022 走看看