把交叉点的坐标求出来即可。

#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的更多相关文章

  1. Rectangle Area——LeetCode

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

  2. [LeetCode] Rectangle Area 矩形面积

    Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...

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

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

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

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

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

    223. 矩形面积 223. Rectangle Area 题目描述 在二维平面上计算出两个由直线构成的矩形重叠后形成的总面积. 每个矩形由其左下顶点和右上顶点坐标表示,如图所示. LeetCode2 ...

  6. [leetcode] Rectangle Area

    Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...

  7. 【leetcode】Contains Duplicate & Rectangle Area(easy)

    Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...

  8. 【刷题-LeetCode】223. Rectangle Area

    Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectang ...

  9. leetcode之Rectangle Area

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

随机推荐

  1. get请求

    写在前面的话 XMLHttpRequest对象的open方法的第一个参数为request-type,取值可以为get或post.本篇介绍get请求. get请求的目的,主要是为了获取数据.虽然get请 ...

  2. 【BZOJ3450】Tyvj1952 Easy 期望DP

    [BZOJ3450]Tyvj1952 Easy Description 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下这个游戏的规则有n次点击要做,成功了就是 ...

  3. Android 蓝牙4.0 BLE

    Android ble (Bluetooth Low Energy) 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用. BLE是蓝牙4.0的核心Profil ...

  4. codeforces round #234B(DIV2) B Inna and New Matrix of Candies

    #include <iostream> #include <vector> #include <string> #include <algorithm> ...

  5. 读书笔记:javascript高级技巧(一)

    一.安全的类型检测 javascript内置的类型检测机制并非完全可靠,由于浏览器或者作用域等原因,经常会发生错误.大家知道,在任何值调用toString()方法都会返回一个[object Nativ ...

  6. 10秒钟安装 Vim编辑器,5分钟浏览常用命令 2015.10.25

    首先我想说,vim与vi的命令几乎相同,,所以学习编辑命令时很轻松,排除扩展相关,以及自动补全等配置的使用在外30秒钟安装 Vim编辑器,5分钟浏览常用命令环境:虚拟机Ubuntu:安装vim并浏览命 ...

  7. 【BZOJ】2216: [Poi2011]Lightning Conductor

    题意 给一个长度为\(n\)的序列\(a_i\),对于每个\(1 \le i \le n\),找到最小的非负整数\(p\)满足 对于任意的\(j\), \(a_j \le a_i + p - \sqr ...

  8. 【POJ】1811 Prime Test

    http://poj.org/problem?id=1811 题意:求n最小素因子.(n<=2^54) #include <cstdio> #include <cstring& ...

  9. GO语言练习:值与引用

    1.代码 2.运行 package main import "fmt" func testValue(){ fmt.Println("for value") v ...

  10. Node.js的函数返回值

    先看一段代码: function select(sqlscript){     var result = "";     sql.connect(config, function( ...