Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the x and y axes.

If there isn't any rectangle, return 0.

Example 1:

Input: [[1,2],[2,1],[1,0],[0,1]]
Output: 2.00000
Explanation: The minimum area rectangle occurs at [1,2],[2,1],[1,0],[0,1], with an area of 2.
Input: [[0,1],[2,1],[1,1],[1,0],[2,0]]
Output: 1.00000
Explanation: The minimum area rectangle occurs at [1,0],[1,1],[2,1],[2,0], with an area of 1. 这题也卡住了,主要是如何判断平面上4个点是矩形? 可以先判断它是个平行四边形,然后判断它的一个角是90度。 x0,x1,x2,x3
y0,y1,y2,y3 首先在不知道顺序的情况下,需要用全部的次序遍历。就是说1,2,3,4; 1,2,4,3;1,4,2,3;1,4,3,2的全排列。 其次判断直角。
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (remove_cv<remove_reference<decltype(b)>::type>::type i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n) class Solution {
public:
double minAreaFreeRect(vector<vector<int>>& points) {
unordered_map<int, unordered_set<int>> c;
for (auto &x:points)c[x[]].insert(x[]);
long n = points.size(), x0, y0, x1, y1,x2,y2,x3,y3, r = LONG_MAX;
REP(i, n) {
x0 = points[i][]; y0 = points[i][];
REP(j, n) {
x1 = points[j][]; y1 = points[j][];
REP(k, n)
if (k != i && k != j) {
x2 = points[k][]; y2 = points[k][];
REP(l, n)
if (l != i && l != j && l != k) {
x3 = points[l][]; y3 = points[l][];
if (x1-x0==x2-x3 && y1-y0==y2-y3 && x3-x0==x2-x1 && y3-y0==y2-y1)
if ((x1-x0)*(x3-x0)+(y1-y0)*(y3-y0)==)
r = min(r, abs((x1 - x0) * (y3 - y0) - (y1 - y0) * (x3 - x0)));
}
}
}
}
return r == LONG_MAX ? : r;
} };

LC 963. Minimum Area Rectangle II的更多相关文章

  1. 【leetcode】963. Minimum Area Rectangle II

    题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...

  2. 963. Minimum Area Rectangle II

    Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these ...

  3. 【LeetCode】963. Minimum Area Rectangle II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线段长+线段中心+字典 日期 题目地址:https: ...

  4. [Swift]LeetCode963. 最小面积矩形 II | Minimum Area Rectangle II

    Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these ...

  5. Leetcode963. Minimum Area Rectangle II最小面积矩形2

    给定在 xy 平面上的一组点,确定由这些点组成的任何矩形的最小面积,其中矩形的边不一定平行于 x 轴和 y 轴. 如果没有任何矩形,就返回 0. 示例 1: 输入:[[1,2],[2,1],[1,0] ...

  6. 计算几何-Minimum Area Rectangle II

    2020-02-10 21:02:13 问题描述: 问题求解: 本题由于可以暴力求解,所以不是特别难,主要是用来熟悉计算几何的一些知识点的. public double minAreaFreeRect ...

  7. 【LeetCode】939. Minimum Area Rectangle 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 确定对角线,找另外两点(4sum) 字典保存出现的x ...

  8. [Swift]LeetCode939. 最小面积矩形 | Minimum Area Rectangle

    Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these p ...

  9. LeetCode - Minimum Area Rectangle

    Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these p ...

随机推荐

  1. mysql 中的 tinyint 字段

    只能存储  -128 ~ 127  之间的数字

  2. linux命令详解——top

    简介 TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系 ...

  3. python list按字典的key值排序

    方法1: result_list = sorted(origin_list, key=lambda e: e.__getitem__('order_key')) 方法2: import operato ...

  4. 第十一章·Filebeat-使用Filebeat收集日志

    Filebeat介绍及部署 Filebeat介绍 Filebeat附带预构建的模块,这些模块包含收集.解析.充实和可视化各种日志文件格式数据所需的配置,每个Filebeat模块由一个或多个文件集组成, ...

  5. deep_learning_Function_Sklearn_Mode

    API参考:https://scikit-learn.org/stable/modules/classes.html# 作为Python中经典的机器学习模块,sklearn围绕着机器学习提供了很多可直 ...

  6. iptables实现内外网端口映射及转发上网

    前两天在工作中遇到一个需求,某192.168.1.0/24内网网段内只有一台主机A连接到了公网,A的两块网卡分别有一个公网地址(123.234.345.456)和一个内网地址(192.168.1.10 ...

  7. z-index无效失效的解决

    解决办法: 父级元素加上position:relative;并设置z-index父级元素的z-index优先,其中包含的元素的z-index是相对于父级元素的index <div style=& ...

  8. P4149 距离为K的点对(最少边数) n=200000 点分治

    这题数据范围变成了200000 n^2就过不了 同时要求求的是最少的边数 不能容斥 #include<bits/stdc++.h> using namespace std; ; ; ], ...

  9. 配置LANMP环境(6)-- 安装APACHE与PHP配置

    一.安装 Apache 2.4 安装:默认安装2.4版本 yum install httpd 修改配置 vim /etc/httpd/conf/httpd.conf 42行80端口改为 8080查看行 ...

  10. R树--理解平面思维

    R树数据结构 备注:参考wiki的内容. 简介 Guttman, A.; “R-trees: a dynamic index structure for spatial searching,” ACM ...