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 ...
随机推荐
- 逆向破解H.Koenig 遥控器 Part 2
逆向破解H.Koenig 遥控器 Part 2 到目前为止,我们已经知道了RF收发器的安装过程,下面是我们所掌握的东西 : l 无线电收发器是一个Avantcom A7105 l 调制是FSK l 频 ...
- visio连接线随形状移动自动伸缩
粘附可保持形状和连接线彼此依附.粘附打开时,可在移动形状时保持连接线跟着一起移动.粘附关闭时,移动形状时连接线将不会跟着移动. 1.在“视图”选项卡上的“视觉帮助”组中,单击对话框启动器 . 2. ...
- python常用模块:sys、os、path、setting、random、shutil
今日内容讲了3个常用模块 一.sys模块二.os模块三.os下path模块四.random模块五.shutil模块 一.sys模块 import sys #环境变量 print(sys.path) # ...
- IDEA中使用Sqlite3
去maven下载驱动包 ( jar包 ) 下载地址:http://mvnrepository.com/artifact/org.xerial/sqlite-jdbc/3.23.1 打开IDEA 创建 ...
- spark 三种数据集的关系(二)
一个Dataset是一个分布式的数据集,而且它是一个新的接口,这个新的接口是在Spark1.6版本里面才被添加进来的,所以要注意DataFrame是先出来的,然后在1.6版本才出现的Dataset,提 ...
- JAVA 日期操作
1.用java.util.Calender来实现 Calendar calendar=Calendar.getInstance(); calendar.setTime(new Date()); Sys ...
- hdu 6059 Kanade's trio
题 OwO http://acm.hdu.edu.cn/showproblem.php?pid=6059 解 由于每个数字最多是30位,枚举数字每一位考虑, 建一棵记录前缀(位的前缀,比如10拆成10 ...
- vue项目,百度地图api高亮选取区域,高亮某个地区,行政区域等
效果如下: var blist = [] ,maxZoom: });// 创建地图实例 var point = new window.BMap.Point(89.48,31.57); map.cent ...
- 【Python之路】特别篇--生成器(constructor)、迭代器(iterator)、可迭代对象(iterable)
生成器(constructor) 生成器函数在Python中与迭代器协议的概念联系在一起.包含yield语句的函数会被特地编译成生成器 !!! 当函数被调用时,他们返回一个生成器对象,这个对象支持迭代 ...
- hadoop安装后运行一个单实例(测试MapReduce程序)
1.安装hadoop 解压hadoop-1.2.1-bin.tar.gz包 tar -zxvf hadoop-1.2.1-bin.tar.gz /opt/modules/ 解压后在/opt/mo ...