国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

223. Rectangle Area

2019-11-08 02:08:16
字體:
來源:轉載
供稿:網友

題目

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.

Rectangle Area 這里寫圖片描述 Assume that the total area is never beyond the maximum possible value of int.

Credits: Special thanks to @mithmatt for adding this PRoblem, creating the above image and all test cases.

Subscribe to see which companies asked this question.


思路

要計算的面積是兩者各自的面積減去覆蓋的面積


代碼

class Solution {public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { //思路:兩者面積和減去覆蓋的面積 int areaA = (C-A)*(D-B); int areaB = (G-E)*(H-F); int left = max(A,E); int right = min(C,G); int bottom = max(B,F); int top = min(D,H); int overloopArea = 0; if(right > left && top > bottom) { overloopArea = (right-left)*(top-bottom); } return areaA+areaB-overloopArea; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新建县| 临沧市| 文安县| 武城县| 江西省| 射洪县| 屯留县| 电白县| 苏尼特右旗| 临西县| 北安市| 黔西县| 蓬安县| 凉城县| 吉水县| 兴安盟| 连平县| 乌什县| 德江县| 馆陶县| 德阳市| 利辛县| 太白县| 东乌珠穆沁旗| 喀喇| 乌拉特前旗| 梁平县| 金沙县| 虹口区| 辽源市| 聊城市| 大庆市| 明水县| 申扎县| 珲春市| 金寨县| 安阳市| 神农架林区| 织金县| 青海省| 陇南市|