leetcode_223. Rectangle Area 求两个矩形覆盖的面积之和
来源:互联网 发布:广电 软件 频道 编辑:程序博客网 时间:2024/06/04 18:42
题目:
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(object):
def computeArea(self, A, B, C, D, E, F, G, H):
"""
:type A: int
:type B: int
:type C: int
:type D: int
:type E: int
:type F: int
:type G: int
:type H: int
:rtype: int
"""
if C<E or D<F or G<A or H<B : #两个矩形不相交,直接返回两个矩形面积之和
return (C-A)*(D-B)+(G-E)*(H-F)
else :
x = min(C,G)-max(A,E) #公共矩形的长
y = min(D,H)-max(B,F) #公共矩形的宽
return (C-A)*(D-B)+(G-E)*(H-F)-x*y #两个大矩形面积减去公共矩形面积
笔记:
刚开始没理解题意,以为是让求两个矩形相交区域的面积,提交一次失败,去网上看其他人方法的时候才明白,是求两个矩形覆盖的面积之和。
- leetcode_223. Rectangle Area 求两个矩形覆盖的面积之和
- Rectangle Area 两个矩形的面积
- Rectangle Area 两个矩形的面积
- LeetCode-223. Rectangle Area (JAVA)求矩形覆盖面积
- (LeetCode)Rectangle Area --- 求图形覆盖的面积
- LeetCode 223. Rectangle Area(两个矩形的复合面积计算)
- 223. Rectangle Area (求两矩形重合部分的面积)
- 求矩形覆盖面积
- Leetcode 223 Rectangle Area 矩形区域面积
- LeetCode 223 Rectangle Area(矩形面积)
- Rectangle Area-带有交差集矩形面积
- leetcode 223. Rectangle Area-矩形面积
- leetcode 223. Rectangle Area 矩形面积计算
- 【uva】11983 求矩形覆盖k次以上的面积
- HDU 5251 矩形面积 (计算几何+旋转卡壳求覆盖凸包的最小矩形面积)
- HDU-1255 覆盖的面积 (线段树 求矩形覆盖面积)
- 如何求两个向交矩形的交集的面积?
- 如何求两个向交矩形的交集的面积?
- node 常用命令
- 关于Xutils框架出现无法访问HttpRequestBase 找不到org.apache.http.client.metho
- XML解析 XML转NSDictionary NSXmlKit
- HttpClient 访问网络
- 解决python2.7中文报错问题
- leetcode_223. Rectangle Area 求两个矩形覆盖的面积之和
- Java中Array.sort()的几种用法
- 单独使用mybatis整合mysql案例
- android设置修改CheckBox框大小、颜色的两种方法
- c++11之模板别名(using)
- Android Studio常用插件(较常用的在前面)
- iOS开发 适配iOS10&Xcode8
- 97条架构建议-业务目标至上-简单可用-亲力亲为
- 布局的小功能合集