Rectangle Area 两个矩形的面积
2015-09-18 11:08
246 查看
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.
class Solution { public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int res=(C-A)*(D-B)+(G-E)*(H-F); int x1,y1,x2,y2; x1=A>E?A:E; y1=B>F?B:F; x2=C<G?C:G; y2=D<H?D:H; if(x1>=x2 || y1>= y2) return res; return res-(x2-x1)*(y2-y1); } };
相关文章推荐
- jfinal与bootstrap的登录跳转实战
- springmvc 自动注入静态service 解决方案
- MySQL5.6 部署MHA
- HDU 5446 Unknown Treasure
- thinkphp 框架去掉bom(当你的网站出现头部有一条空白)
- 诗是开满花的海
- ViewGroup 详解
- TCP三次握手/四次挥手详解
- 内核导言之操作系统体系结构
- CoreText文字排版
- Reverse Linked List 链表逆转 简单题
- iScroll.js 用法参考 (share)
- OC实现个人中心页面
- .net socket 层面实现代理服务器
- pdf文件转换成jpg方法详解
- 安装MongoDB配置ReplicaSet
- 安卓接口回调
- 第三周项目2—— 建设“顺序表”算法库
- 七款Debug工具推荐:iOS开发必备的调试利器
- Eclipse导入Maven项目并启动的步骤