223 Rectangle Area 矩形面积
在二维平面上计算出两个由直线构成的矩形叠加覆盖后的面积。
假设面积不会超出int的范围。
详见:https://leetcode.com/problems/rectangle-area/description/
Java实现:
class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int sum = (C - A) * (D - B) + (H - F) * (G - E);
if (E >= C || F >= D || B >= H || A >= G){
return sum;
}
return sum - ((Math.min(G, C) - Math.max(A, E)) * (Math.min(D, H) - Math.max(B, F)));
}
}
C++实现:
class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int sum = (C - A) * (D - B) + (H - F) * (G - E);
if (E >= C || F >= D || B >= H || A >= G)
{
return sum;
}
return sum - ((min(G, C) - max(A, E)) * (min(D, H) - max(B, F)));
}
};
参考:https://www.cnblogs.com/grandyang/p/4563153.html
223 Rectangle Area 矩形面积的更多相关文章
- [LeetCode] 223. Rectangle Area 矩形面积
Find the total area covered by two rectilinearrectangles in a 2D plane. Each rectangle is defined by ...
- [LeetCode]223. Rectangle Area矩形面积
/* 像是一道数据分析题 思路就是两个矩形面积之和减去叠加面积之和 */ public int computeArea(int A, int B, int C, int D, int E, int F ...
- [LeetCode] Rectangle Area 矩形面积
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...
- (easy)LeetCode 223.Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
- 【刷题-LeetCode】223. Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- [HDU 4419] Colourful Rectangle (扫描线 矩形面积并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4419 题目大意:比矩形面积并多了颜色,问染成的每种颜色的面积. 矩形面积并的扫描线维护的是长度,这道题 ...
- LeetCode 223 Rectangle Area(矩形面积)
翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究 ...
- 223. Rectangle Area
题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defin ...
- LeetCode OJ 223.Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
随机推荐
- VM虚拟机ping不通局域网其他主机的解决办法
1 我的笔记本的无线网卡是自动获取IP,并且是通过无线网卡上网. 2 我的有线网卡是通过自己设定IP跟局域网的其他机器连通.当前设定的IP为172.16.17.2 3我需要连接的局域网另一个主 ...
- SonarQube---在具体项目中的使用
一.简介 SonarQube(简称Sonar)是管理代码质量的开放平台,它可以快速地对代码质量进行分析,并给出合理的解决方案,提高管理效率,保证代码质量. Sonar官网,文档 Sonar Scann ...
- 谈谈TensorFlow with CPU support or TensorFlow with GPU support(图文详解)
不多说,直接上干货! You must choose one of the following types of TensorFlow to install: TensorFlow with CPU ...
- my-small.cnf my-medium.cnf my-large.cnf my-huge.cnf
my-small.cnf my-medium.cnf my-large.cnf my-huge.cnf 是 MySQL 默认的几个配置文件.针对不同配置的服务器可以使用不同的配置文件,将你需要的那一个 ...
- OpenTK的glutBitmapCharacter的替代方法
由于openTK并没有打包集成GLUT,字体显示就成了一个问题. 办法1:采用QuickFont 优点:可以使用系统自带的字体 缺点:代码尚未成熟.只能2D显示,无法随物体旋转.平移 办法2:同时调用 ...
- ASP.NET MVC中为DropDownListFor设置选中项的方法
在MVC中,当涉及到强类型编辑页,如果有select元素,需要根据当前Model的某个属性值,让Select的某项选中.本篇只整理思路,不涉及完整代码. □ 思路 往前台视图传的类型是List< ...
- unable to instantiate activity...
Activity跳转到Activity,后来由于项目需要将第二个Activity改成继承FragmentActivity,跳转报错...无法初始化Activity,找不到class云云.. 最后是将b ...
- Django's CSRF mechanism
Forbidden (403) CSRF verification failed. Request aborted. You are seeing this message because this ...
- Lightoj 1012 - Guilty Prince
bfs遍历一遍就行了. /* *********************************************** Author :guanjun Created Time :2016/6/ ...
- vmware中鼠标在部分区域不能使用
https://blog.csdn.net/dreamengsoul/article/details/80439278 方法1:重装VMware tools; 方法2:使用增强型键盘鼠标: 方法3:检 ...