Rectangle Area
2015-09-16 01:11
281 查看
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 int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int areaOfSqrA = (C - A) * (D - B); int areaOfSqrB = (G - E) * (H - F); int left = Math.max(A, E); int right = Math.min(G, C); int bottom = Math.max(F, B); int top = Math.min(D, H); // If overlap int overlap = 0; if (right > left && top > bottom) overlap = (right - left) * (top - bottom); return areaOfSqrA + areaOfSqrB - overlap; }
相关文章推荐
- IOS征途之三 分类与协议
- maven jetty myeclipse 进行debug
- TCP协议流量控制与拥塞避免【转载】
- Activity 通过 Fragment保存大块数据的一种方法。摘自android开发官网 3ff8
- Win10实现窗口AeroGlass化
- word frequency
- android 状态栏一体化实现
- Adapter&&GroupAdapter&&VerifyAdapter&&PicAdapter
- storm-kafka数据流量问题
- MySQL5.6 部署MHA
- android网络游戏开发——网络通信——IO处理
- 设计模式学习笔记二十六:装饰器模式
- HDU 1695 GCD(莫比乌斯反演)
- Java9: REPL环境与编程
- java
- 【剑指Offer】矩形覆盖
- 在openwrt中对https 数据的转发到 云端
- 引用一个项目作为library的操作步骤---开发中遇到的问题(二)
- UVALive 3938 Ray, Pass me the dishes (线段树区间合并)
- 引用一个项目作为library的操作步骤---开发中遇到的问题(二)