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. linux 命令技巧(转)--history

    本文介绍一些关于bash的能够提高效率的技巧,主要是关于历史命令操作和一些快捷键,让你在命令行下工作效率翻倍. 1.history-----最基本的查看历史命令 2.!n-----编号为n的历史命令 ...

  2. Beta冲刺版本第二天

    该作业所属课程:https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 作业要求地址:https://edu.cnblogs.com ...

  3. 【杭电多校第七场】A + B = C

    原题: Given a,b,c, find an arbitrary set of x,y,z such that a*10^x+b*10^y=c*10^z and 0≤x,y,z≤10^6. 给你三 ...

  4. libusb_bulk_transfer返回值不是0

    libusb_bulk_transfer返回值不是0 libusb_bulk_transfer返回值不是0libusb_bulk_transfer返回值不是0 ?????

  5. Python之文字转图片

    Pygame模块一览表: 引入pygame模块 ,若本机没有请自行pip install pygame #载入必要的模块 import pygame #pygame初始化 pygame.init() ...

  6. redis实现排行榜功能

    目录 加入排行榜 操作排行榜 redis的zset可以很方便地用来实现排行榜功能,下面简单介绍python如何使用redis实现排行榜功能 加入排行榜 获取redis实例 import redis m ...

  7. python--AutoPy库

    包括用于控制键盘和鼠标,在屏幕上查找颜色和位图以及显示警报的功能 - 所有这些都是以跨平台,高效和简单的方式进行的.适用于Mac OS X,Windows和X11 中文文档:https://blog. ...

  8. 【51nod 1847】奇怪的数学题

    题目描述 给出 N,K ,请计算下面这个式子: \(∑_{i=1}^N∑_{j=1}^Nsgcd(i,j)^k\) 其中,sgcd(i, j)表示(i, j)的所有公约数中第二大的,特殊地,如果gcd ...

  9. hdu 6039 Gear Up

    题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6039 (2017 Multi-University Training Contest 1 1007) ...

  10. C# 常用方法——base64字符串转图片

    其他常用方法详见:https://www.cnblogs.com/zhuanjiao/p/12060937.html /// <summary> /// base64编码的文本转为图片 / ...