计算几何-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 ...
随机推荐
- 在没有APP的125年前 印度的外卖小哥是这样送餐
说到印度,你想到的是什么?咖喱.歌舞剧.开挂的火车?通通不是,我今天要说的是他们的外卖小哥,在印度如同"神"一般的存在.其实印度人不叫这批人为外卖小哥,而称他们为dabbawala ...
- scss入门学习(一)
sass的文件后缀名 sass是目前流行的css预处理语言.sass有两种后缀文件,一种是.sass,不允许使用大括号和分号:另一种是.SCSS,允许使用大括号和分号,类似于我们平时写css的语法习惯 ...
- flutter 入门(Mac)
背景 近一年时间都在用 React Native 开发公司的 APP,水平基本上可以说是登堂入室了.前一段时间兴起一阵 Flutter 热,后端的同事都有推荐,今年 Google 大会又推出 flut ...
- 迈克尔·乔丹:几百年内AI不会觉醒
此乔丹非飞人乔丹.他是研究统计学和计算机科学家,目前研究的领域正是普通人所说的人工智能.权威的学术搜索引擎Semantic Scholar在2105年做了一项排名,关于计算机科学领域谁最具影响力 ...
- Python——9函数式编程②
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...
- C++学习之旅
到现在为止学习C++也已经有一个半月了.一个半个月里我怀着好奇与敬畏一步步的走来,一步步的走向C++的内心深处,也发现了C++"内心的复杂".虽有坎坷,但从未放弃. 我承认,我不是 ...
- django之学习前的准备
一.配置环境 Windows 10操作系统 Python安装配置教程参考:https://www.cnblogs.com/huangbiquan/p/7784533.html 安装Python虚拟环境 ...
- 设计模式-09装饰模式(Decorator Pattern)
1.模式动机 一般有两种方式可以实现给一个类或对象增加行为: 继承机制:使用继承机制是给现有类添加功能的一种有效途径,通过继承一个现有类可以使得子类在拥有自身方法的同时还拥有父类的方法.但是这种方法是 ...
- property 属性
#propery 属性"""内置装饰器函数,只在面向对象中使用."""#计算圆的面积,圆的周长 from math import pi cl ...
- Spring,SpringMVC,MyBatis,SSM配置文件比较
Spring配置文件: applicationContext.xml applicationContext.xml是Spring的核心配置文件 IOC/DI,AOP相关配置都是在这个文件中 Sprin ...