Rectangle Area
2015-12-11 15:34
274 查看
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.
class Solution { public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int result = (C-A)*(D-B) + (G-E)*(H-F); int A1 = max(A,E); int B1 = max(B,F); int C1 = min(C,G); int D1 = min(D,H); if(C1<=A1 || D1<=B1) return result; else return result - (C1-A1)*(D1-B1); } };
相关文章推荐
- 编译器错误消息: CS1617: 选项“6”对 /langversion 无效
- Failed to create the part's controls
- 1019. 数字黑洞
- linux内核构成
- activeMQ 示例
- 线程Looper+Handler+Thread学习
- Android Toast
- Xcode高级调试技巧4
- 数据结构与内存中的堆与栈
- 如果查看应用性能图表是一种信仰
- android学习--使用adb工具管理sqlite3数据库
- Android 自定义imageview图片高度固定大小宽度按比例自适应
- Ajax跨域、Json跨域、Socket跨域和Canvas跨域等同源策略限制的解决方法
- java实现sms短信发送
- [Canvas绘图] 第25节 藏图阁(10) 厨房电器
- IOS-41-NSTimer定时器的使用
- 实现图片放大缩小,点击热点响应事件
- SVN导出/导入、SVN备份/还原 【小白版】
- Android 实现两屏幕互相滑动
- pom.xml