1. 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.

Example:

Input: A = -3, B = 0, C = 3, D = 4, E = 0, F = -1, G = 9, H = 2
Output: 45

Note:

Assume that the total area is never beyond the maximum possible value of int.

计算公式为:S = 矩形1的面积 + 矩形2的面积 - 相交部分的面积

相交的宽 = 矩形1的宽 + 矩形2的宽 - 实际图形的宽

相交的高计算类似

如果相交部分的高或者宽小于0,说明没有相交

题目原本定义的int会溢出???????

typedef long long int LL;
class Solution {
public:
LL computeArea(LL A, LL B, LL C, LL D, LL E, LL F, LL G, LL H) {
LL S = (C-A)*(D-B) + (G-E)*(H-F);
LL d = abs(C - A) + abs(G - E) - abs(max(G, C) - min(A, E));
LL h = abs(D - B) + abs(H - F) - abs(max(D, H) - min(F, B));
return S - (d > 0 && h > 0 ? d * h : 0);
}
};

【刷题-LeetCode】223. Rectangle Area的更多相关文章

  1. [LeetCode] 223. Rectangle Area 矩形面积

    Find the total area covered by two rectilinearrectangles in a 2D plane. Each rectangle is defined by ...

  2. Java for LeetCode 223 Rectangle Area

    Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...

  3. (easy)LeetCode 223.Rectangle Area

    Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...

  4. Java [Leetcode 223]Rectangle Area

    题目描述: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is def ...

  5. LeetCode 223 Rectangle Area(矩形面积)

    翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...

  6. [LeetCode]223. Rectangle Area矩形面积

    /* 像是一道数据分析题 思路就是两个矩形面积之和减去叠加面积之和 */ public int computeArea(int A, int B, int C, int D, int E, int F ...

  7. LeetCode : 223. Rectangle Area

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABRQAAAQ0CAYAAAAPPZBqAAAMFGlDQ1BJQ0MgUHJvZmlsZQAASImVlw

  8. LeetCode刷题------------------------------LeetCode使用介绍

    临近毕业了,对技术有种热爱的我也快步入码农行业了,以前虽然在学校的ACM学习过一些算法,什么大数的阶乘,dp,背包等,但是现在早就忘在脑袋后了,哈哈,原谅我是一枚菜鸡,为了锻炼编程能力还是去刷刷Lee ...

  9. [LeetCode] 850. Rectangle Area II 矩形面积之二

    We are given a list of (axis-aligned) rectangles.  Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...

随机推荐

  1. CF1106A Lunar New Year and Cross Counting 题解

    Content 试求出在一个 \(n\times n\) 的地图 \(M\) 中,满足 \(1\leqslant i,j\leqslant n\) 且 \(M_{i,j}=M_{i+1,j+1}=M_ ...

  2. CF208A Dubstep 题解

    Content 有一个字符串被变换了.其中在这个字符串的前面加了 \(\geqslant 0\) 个 WUB,每个单词(由空格间隔)之间加了 \(\geqslant 1\) 个 WUB,在这个字符串的 ...

  3. Vue3.0是如何变快的

    1.diff算法优化 + Vue2中的虚拟dom是进行全量的对比 https://vue-next-template-explorer.netlify.app/ + Vue3新增了静态标记(Patch ...

  4. git pull 拉取报错:fatal: refusing to merge unrelated histories

    fatal: refusing to merge unrelated histories(拒绝合并不相关的历史) 使用 git pull origin master --allow-unrelated ...

  5. git命令行常用操作总结

    关于 更多使用细节(grammar和book),请参考 官网 1.上传代码 1.1 创建自己的远程Repository, github或者gitee 1.2 创建本地git仓库 $ git init ...

  6. 【LeetCode】7. Reverse Integer 整数反转

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:整数,反转,题解,Leetcode, 力扣,Python, ...

  7. 后缀数组【原理+python代码】

    后缀数组 参考:https://blog.csdn.net/a1035719430/article/details/80217267 https://blog.csdn.net/YxuanwKeith ...

  8. [数学]高数部分-Part VI 重积分

    Part VI 重积分 回到总目录 Part VI 重积分 二重积分的普通对称性 二重积分的轮换对称性(直角坐标系下) 二重积分直角坐标系下的积分方法 二重积分极坐标系下的积分方法 二重积分中值定理 ...

  9. [opencv]Rect集合象限法分类聚合 函数

    /** * 矩形拟合 * @param mats * @return */ vector<Rect> PublicCardFrameDetection::RectContainFit(ve ...

  10. Vue.js高效前端开发 • 【Vue列表渲染】

    全部章节 >>>> 文章目录 一.v-for指令 1.v-for指令使用 2.实践练习(待更新) 二.计算属性 1.计算属性创建和使用 2.实践练习(待更新) 三.侦听属性 1 ...