Find the total area covered by two rectilinear rectangles in a 2D plane. 208MM
2015-06-08 22:07
537 查看
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.
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; } } //没考虑清楚,求面积不用判断符号,没有啥捷径目前发现 分析各种情况,总结条件,编写代码 有点像设计数字电路
相关文章推荐
- 初学Spark
- 分页例子
- 技术人员获得高薪有哪些谈判技巧?
- 采集和输出 DeckLink Studio 4K
- 使用bat文件实现批量重命名功能
- [LeetCode] Linked List Cycle
- CompositeSenone API
- Android中几种字符串拼接的效率比较
- PHP开发使用xampp搭建本地开发环境
- make_heap topk 问题
- 狂刷Android范例之2:剪贴板范例
- ABP(现代ASP.NET样板开发框架)系列之7、ABP Session管理
- jquery中ajax 从前端到后端 完整过程解析
- openssl开源程序dh算法解析之dh_key.c
- 第一题
- AcousticModel API 声学模型
- C++二叉查找树实现过程详解
- 阿猿,你的工作在混日子吗?
- Android 清理应用缓存
- Rectangle Area - LeetCode 223