有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域。
每个矩形用左下角的点和右上角的点的坐标来表示。例如, 一个单位正方形可以表示为 [1,1,2,2]。 ( 左下角的点的坐标为 (1, 1) 以及右上角的点的坐标为 (2, 2) )。

详见:https://leetcode.com/problems/perfect-rectangle/description/

C++:

    class Solution {
public:
bool isRectangleCover(vector<vector<int>>& rectangles) {
unordered_map<string, int> hash;
for(auto val: rectangles)
{
for(int i = 0; i < 4; i++)
{
string tem = to_string(val[i/2*2])+','+to_string(val[i%2*2+1]);
if(hash[tem]&(1<<i))
{
return false;
}
hash[tem] |= (1<<i);
}
}
int cntCorner = 0;
for(auto& val: hash)
{
int sec = val.second;
if(!(sec&(sec-1)) && cntCorner++ > 4)
{
return false;
}
if((sec&(sec-1)) && !(sec==3||sec==12||sec==5||sec==10||sec==15))
{
return false;
}
}
return true;
}
};

参考:https://blog.csdn.net/qq508618087/article/details/52483625

391 Perfect Rectangle 完美矩形的更多相关文章

  1. [LeetCode] Perfect Rectangle 完美矩形

    Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...

  2. Perfect Rectangle(完美矩形)

    我们有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域. 每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 [1,1,2,2] ...

  3. 391. Perfect Rectangle

    最后更新 一刷 16-Jan-2017 这个题我甚至不知道该怎么总结. 难就难在从这个题抽象出一种解法,看了别人的答案和思路= =然而没有归类总结到某种类型,这题相当于背了个题... 简单的说,除了最 ...

  4. Java实现 LeetCode 391 完美矩形

    391. 完美矩形 我们有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域. 每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 ...

  5. Leetcode 391.完美矩形

    完美矩形 我们有 N 个与坐标轴对齐的矩形, 其中 N > 0, 判断它们是否能精确地覆盖一个矩形区域. 每个矩形用左下角的点和右上角的点的坐标来表示.例如, 一个单位正方形可以表示为 [1,1 ...

  6. [Swift]LeetCode391. 完美矩形 | Perfect Rectangle

    Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...

  7. [LeetCode] Rectangle Area 矩形面积

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

  8. [LeetCode] Maximal Rectangle 最大矩形

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  9. Perfect Scrollbar – 完美的 jQuery 滚动条插件

    Perfect Scrollbar 是一个很小的,但完美的 jQuery 滚动插件.滚动条不会影响原来的设计布局,滚动条的设计是完全可定制的.你可以改变几乎所有的 CSS 样式的滚动条,滚动条设计对脚 ...

随机推荐

  1. 更新数据库中数据时出现: Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences 问题

    使用workbench在数据库中更新数据时报错: You are using safe update mode and you tried to update a table without a WH ...

  2. Ubuntu 16.04出现chmod: 无效模式:"a"的问题解决

    命令: chmod a+x file1 提示:注意文件的类型,如果用在文件夹上是不行的,但是文件确实可以的.

  3. Windows 10+Ubuntu 16.04在MBR分区上安装双系统之后启动菜单的System Setup选项提示:can't find command "fwsetup"

    背景: 硬盘分区方式:MBR 硬盘容量256,Windows 100,Ubuntu 156,其中主分区安装的是Windows,Ubuntu安装在逻辑分区上,文件系统为Ext4,整个Ubuntu就挂载在 ...

  4. MongoDB小结07 - update【$addToSet & $each】

    用$addToSet更新可以避免重复,将它与$each组合起来,可以一次性添加多条(就算后添加的值已存在也没有关系) db.user.update({"name":"co ...

  5. select语句中会影响查询效率的因素

    1.没有创建索引,或者没有正确使用索引;2.存在死锁的情况,从而导致select语句挂起; 3.返回不必要的列,如很多人喜欢在程序中使用select * from 这样会查询表或视图中的所有字段,如果 ...

  6. vue assetsPublicPath

    vue 中 /config/index.js,  assetsPublicPath 的作用是便于访问打包后的静态资源,默认是相对于根 /, 当然如果直接把dist文件夹当成根来配置域名 可以什么都不用 ...

  7. vijos - P1447开关灯泡 (大数模板 + 找规律 + 全然数 + python)

    P1447开关灯泡 Accepted 标签:CSC WorkGroup III[显示标签] 描写叙述 一个房间里有n盏灯泡.一開始都是熄着的,有1到n个时刻.每一个时刻i,我们会将i的倍数的灯泡改变状 ...

  8. Sound Card Chip

      DELL sigmatel stac   Hewlett-packard conexant High Definition Audio chip   lenovo(IBM) Analo Devic ...

  9. Android Studio 1.x 使用问题汇总

    Android Studio是谷歌于13年I/O大会推出的Android开发环境,基于IntelliJ IDEA. 类似 Eclipse ADT,Android Studio 提供了集成的Androi ...

  10. 使用Charles进行网络抓包

    一.安装Charles 二.使用 1.http抓包 1.1 现在我们默认是在进行iOS开发,首先确保iPhone和Mac是在同一个局域网下(连同一个WiFi).然后查看Mac的IP地址(打开网络偏好设 ...