Rectangle Area || LeetCode
把交叉点的坐标求出来即可。
#define max(a,b) ( (a)>(b)?(a):(b) )
#define min(a,b) ( (a)<(b)?(a):(b) )
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int downx,downy,upx,upy;
int crossArea;
int all;
downx=max(A,E);
downy=max(B,F);
upx =min(C,G);
upy =min(D,H);
if(downx>upx||downy>upy)crossArea=0;
else crossArea=(upx-downx)*(upy-downy);
all=(C-A)*(D-B)+(G-E)*(H-F);
return all-crossArea;
}
Rectangle Area || LeetCode的更多相关文章
- Rectangle Area——LeetCode
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
- [LeetCode] Rectangle Area 矩形面积
Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...
- [LeetCode] 850. Rectangle Area II 矩形面积之二
We are given a list of (axis-aligned) rectangles. Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...
- [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)
223. 矩形面积 223. Rectangle Area 题目描述 在二维平面上计算出两个由直线构成的矩形重叠后形成的总面积. 每个矩形由其左下顶点和右上顶点坐标表示,如图所示. LeetCode2 ...
- [leetcode] Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- 【leetcode】Contains Duplicate & Rectangle Area(easy)
Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...
- 【刷题-LeetCode】223. Rectangle Area
Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...
- leetcode之Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined b ...
随机推荐
- java-类
浏览以下内容前,请点击并阅读 声明 java是面向对象的语言,而对象的创建,则需要借助类,类可以说是一个创建对象的模具(个人理解). 类的定义 以下构成定义类的最简单(不能再简单)语句: class ...
- Backbone.js学习之二
经历一段自我修炼,终于领悟到Backbone.js的关键知识点,也发现了原来MVC可以在前端这样梦幻的发挥,Backbone.js确实是一个很有魅力的前端MVC框架. 练就一门技术,需要有扎实的功底, ...
- Understanding the WPF Layout System
Many people don't understand how the WPF layout system works, or how that knowledge can help them in ...
- ural 1339. Babies
1339. Babies Time limit: 1.0 secondMemory limit: 64 MB O tempora! O mores! Present-day babies progre ...
- python 代码片段24
#coding=utf-8 #内部类 class MyClass(object): class InnerClass: pass # 正则表达式 # 通过re模块来访问 import re m=re. ...
- Android数据存储的三种方式:SharePreferences , file , SQLite
(1)SharePreferences: 存入: SharedPreferences setter = this.getSharedPreferences("spfile", 0) ...
- css3+js打造炫酷图片展示
<!DOCTYPE html> <html onselectstart="return false"> <!-- onselectstart=&quo ...
- nfs的使用
1.安装命令:sudo apt-get install nfs-kernel-server ; sudo apt-get install nfs-common; 2.执行命令:mkdir /(目录 ...
- Node.js 手册查询-2-MongoDB数据库方法
MongoDb 标签(空格分隔): 数据库 MongoDb 安装 当前版本 2.X 解压至任意目录,最好不要是c盘. 在根目录下建立一个文件夹用来存储工程 我的例子: 安装至: d:\mongodb ...
- [LintCode] Letter Combinations of a Phone Number 电话号码的字母组合
Given a digit string, return all possible letter combinations that the number could represent. A map ...