LC 963. Minimum Area Rectangle II
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的更多相关文章
- 【leetcode】963. Minimum Area Rectangle II
题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...
- 963. Minimum Area Rectangle II
Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these ...
- 【LeetCode】963. Minimum Area Rectangle II 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线段长+线段中心+字典 日期 题目地址:https: ...
- [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 ...
- Leetcode963. Minimum Area Rectangle II最小面积矩形2
给定在 xy 平面上的一组点,确定由这些点组成的任何矩形的最小面积,其中矩形的边不一定平行于 x 轴和 y 轴. 如果没有任何矩形,就返回 0. 示例 1: 输入:[[1,2],[2,1],[1,0] ...
- 计算几何-Minimum Area Rectangle II
2020-02-10 21:02:13 问题描述: 问题求解: 本题由于可以暴力求解,所以不是特别难,主要是用来熟悉计算几何的一些知识点的. public double minAreaFreeRect ...
- 【LeetCode】939. Minimum Area Rectangle 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 确定对角线,找另外两点(4sum) 字典保存出现的x ...
- [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 ...
- LeetCode - Minimum Area Rectangle
Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these p ...
随机推荐
- JavaJDBC【四、存储过程的使用】
Mysql还没学到存储过程,不过语法比较简单 此处不深究数据库中的存储过程怎么创建,后面在mysql的学习笔记里再做整理 今天只整理java中如何调用存储过程 语句 CallableStatement ...
- 【5】Zookeeper的ZAB协议
一.ZAB协议(原子消息广播协议) ZAB(Zookeeper Atomic Broadcast)协议是Zookeeper用来保证其数据一致性的核心算法,是一种支持崩溃恢复的原子广播协议.基于此协 ...
- C语言的宏macro的使用
C's Macro Introduction 1.The Connect Macros: ## 这是一个预处理连接符,这个操作符主要用来将两个符号连接成为一个完整的宏符号.通过下面的代码,可以看到其具 ...
- linux下安装google-chrome浏览器和chromedriver
1.root用户下进入到etc/yum.repos.d目录下 [root@f7d6b9f2-1291-4d2f-8805-aef94deac9f7 yum.repos.d]# pwd cd /etc/ ...
- Linux配置JDK环境
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-co ...
- MLE vs MAP: the connection between Maximum Likelihood and Maximum A Posteriori Estimation
Reference:MLE vs MAP. Maximum Likelihood Estimation (MLE) and Maximum A Posteriori (MAP), are both a ...
- linux下安装压缩解压程序7z命令及7z命令的使用
1.1 在线安装如果你的宿主机Linux可以连接外网,推荐用这种方式,方便简单,执行命令:sudo apt-get install p7zip即可在线安装7z命令. 1.2 安装包安装7z(准确点说是 ...
- 关于layui表格渲染templet解析单元格的问题
原文链接:https://blog.csdn.net/wyp_comeon/article/details/81735951关于表格解析自定义单元格的解析参数请先详细查看官方文档:http://www ...
- java程序连接Liunx服务器并且执行命令
JSch 介绍 JSch 是SSH2的一个纯Java实现.它允许你连接到一个sshd 服务器,使用端口转发,X11转发,文件传输等等.你可以将它的功能集成到你自己的 程序中.同时该项目也提供一个J2M ...
- js获取服务器端时间
第一种: $.ajax({ type:"OPTIONS", url:"/", complete:function(x){ var date = x.getRes ...