计算几何-Minimum Area Rectangle II
2020-02-10 21:02:13
问题描述:


问题求解:
本题由于可以暴力求解,所以不是特别难,主要是用来熟悉计算几何的一些知识点的。
public double minAreaFreeRect(int[][] points) {
double res = 2e9;
Map<Integer, Set<Integer>> record = new HashMap<>();
for (int[] p : points) {
int x = p[0];
int y = p[1];
if (!record.containsKey(x)) record.put(x, new HashSet<>());
record.get(x).add(y);
}
int n = points.length;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
if (check(points[i], points[j], points[k]) && record.containsKey(points[j][0] + points[k][0] - points[i][0]) && record.get(points[j][0] + points[k][0] - points[i][0]).contains(points[j][1] + points[k][1] - points[i][1])) {
res = Math.min(res, area(points[i], points[j], points[k]));
}
}
}
}
return res == 2e9 ? 0 : res;
}
private boolean check(int[] p1, int[] p2, int[] p3) {
return (p2[0] - p1[0]) * (p3[0] - p1[0]) + (p2[1] - p1[1]) * (p3[1] - p1[1]) == 0;
}
private double area(int[] p1, int[] p2, int[] p3) {
return Math.abs(p1[0] * p2[1] + p1[1] * p3[0] + p2[0] * p3[1] -
p2[1] * p3[0] - p1[1] * p2[0] - p1[0] * p3[1]);
}
计算几何-Minimum Area Rectangle II的更多相关文章
- [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 ...
- 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 ...
- 【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: ...
- Leetcode963. Minimum Area Rectangle II最小面积矩形2
给定在 xy 平面上的一组点,确定由这些点组成的任何矩形的最小面积,其中矩形的边不一定平行于 x 轴和 y 轴. 如果没有任何矩形,就返回 0. 示例 1: 输入:[[1,2],[2,1],[1,0] ...
- 【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 ...
随机推荐
- 递归加法(day1)
题目:求1+2+-+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字以及条件判断语句(A?B:C). 使用函数指针 1 2 3 4 5 6 7 8 9 10 ...
- 安卓权威编程指南-笔记(第27章 broadcast intent)
本章需求:首先,让应用轮询新结果并在有所发现时及时通知用户,即使用户重启设备后还没有打开过应用.其次,保证用户在使用应用时不出现新结果通知. 1. 一般intent和broadcast intent ...
- js中的函数应用
js中的函数应用 什么是函数,函数的概念 函数就像一个黑匣子,里面的东西你都不知道,但是你提供一些材料放进去,他可以制造出你需要的东西; 可以让多个一样的功能封装组合起来,然后想执行几次就执行几次 函 ...
- LeetCode--链表1-单链表
LeetCode--链表1-单链表 单链表模板 初始化 头部插入 尾部插入 删除节点 Index插入 Index返回对应的节点指针和val值 class MyLinkedList { private: ...
- beego的安装以及bee的安装和使用
beego的安装以及bee的安装和使用 一.beego的安装 1.beego是什么 beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API.Web 及后端服务等各种应用, ...
- 微信小程序学习 动手撸一个校园网小程序
动手撸一个校园网微信小程序 高考完毕,想必广大学子和家长们都在忙着查询各所高校的信息,刚好上手微信小程序,当练手也当为自己的学校做点宣传,便当即撸了一个校园网微信小程序. 效果预览 源码地址:Gith ...
- LeetCode 33.Search in Rotated Sorted Array(M)
题目: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. ( ...
- golang切片
切片与数组 go的数组是这样的 array := [3]int{1,2,3} array := [...]int{1,2,3} go的切片 array := []int{1,2,3} //1 arra ...
- Could not find a valid gem 'redis' (= 0)
Could not find a valid gem 'redis' (= 0) 报错详情如下: ERROR: Could not find a valid gem 'redis' (>= 0) ...
- docker 学习路线
docker 学习路线 参考资料 知乎 docker 的学习路线 Docker - 从入门到实践 Docker 核心技术与实现原理 Docker 入门 <Kubernetes in Action ...