Rectangle Area
2015-12-03 18:36
211 查看
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 = (D - B) * (C - A) + (H - F) * (G - E);
int A1 = max(A, E), B1 = max(B, F), C1 = min(C, G), D1 = min(D, H);
if (D1 <= B1 || C1 <= A1) return res;
return res - (D1 - B1) * (C1 - A1);
}
};
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 = (D - B) * (C - A) + (H - F) * (G - E);
int A1 = max(A, E), B1 = max(B, F), C1 = min(C, G), D1 = min(D, H);
if (D1 <= B1 || C1 <= A1) return res;
return res - (D1 - B1) * (C1 - A1);
}
};
相关文章推荐
- Java的Struts框架中的if/else标签使用详解
- android More Resource Types
- TCP流量控制机制
- html5学习笔记(2)
- 最简单的qps统计方法
- UITabBarController的每个item的title如何不占位置
- java中try-catch语句的使用
- UIImagePickerController 原帖地址:http://blog.csdn.net/kingsley_cxz/article/details/9157093
- ios 开发中,如何设置 uitabbar 里面 tabbaritem 不显示文字,只显示图片,图片垂直居中?
- html5学习笔记(1)
- 通而不达网络的发现与解决方案
- 常用的iOS开源库
- android-Style Resource
- NOIp2015提高组 解题报告
- Discuz!NT Flash无法上传头像,点击上传后无任何反应
- GIF 屏幕录制工具
- NSDate&NSString
- android SD卡 数据存储代码
- easyui 合并单元格
- 无法根据中文查找