国产探花免费观看_亚洲丰满少妇自慰呻吟_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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乐平市| 桦南县| 江油市| 杭锦旗| 长垣县| 永城市| 泾阳县| 灯塔市| 湾仔区| 梅河口市| 阿克苏市| 娱乐| 阜平县| 孟州市| 时尚| 洛宁县| 赣榆县| 赣榆县| 洪洞县| 黄龙县| 富锦市| 南宁市| 龙门县| 龙井市| 兴隆县| 呼伦贝尔市| 兴安盟| 汕尾市| 仲巴县| 宁城县| 城固县| 自贡市| 延寿县| 靖江市| 太仓市| 新竹市| 鹰潭市| 马边| 建阳市| 财经| 信丰县|