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的更多相关文章

  1. [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 ...

  2. 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 ...

  3. 【leetcode】963. Minimum Area Rectangle II

    题目如下: Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from ...

  4. 963. Minimum Area Rectangle II

    Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these ...

  5. 【LeetCode】963. Minimum Area Rectangle II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 线段长+线段中心+字典 日期 题目地址:https: ...

  6. Leetcode963. Minimum Area Rectangle II最小面积矩形2

    给定在 xy 平面上的一组点,确定由这些点组成的任何矩形的最小面积,其中矩形的边不一定平行于 x 轴和 y 轴. 如果没有任何矩形,就返回 0. 示例 1: 输入:[[1,2],[2,1],[1,0] ...

  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. 1078 Hashing (25 分)

    1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive integ ...

  2. C++与引用1

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  3. 创建SpringMVC项目过程

    1.导入对应jar包 <properties> <spring.version>5.0.2.RELEASE</spring.version> </proper ...

  4. java集合-set

    #java集合-set Map用于存储key-value的映射,其中key的值是不能重复的.并且还需要正确的覆写equals方法和hashCode方法 如果我们只需要存储不重复的key,并不需要存储对 ...

  5. spring jpa ManyToMany 理解和使用

    1.java和jpa 中所有的关系都是单向的.这个关系数据库不同,关系数据库,通过外键定义并查询,使得反向查询总是存在的. 2.JPA还定义了一个OneToMany关系,它与ManyToMany关系类 ...

  6. idea通过maven打jar包不成功或无法加载主类或打成功也找不到jar包

    这个问题纠结了我一天,在网上也搜了一些方法,现在把我自己的处理过程记录一下,以方便遇到此类问题的小伙伴参考: 第一步:查看idea的jdk版本与Windows安装的jdk是不是同一个版本,如下图 第二 ...

  7. java反序列化-ysoserial-调试分析总结篇(7)

    前言: CommonsCollections7外层也是一条新的构造链,外层由hashtable的readObject进入,这条构造链挺有意思,因为用到了hash碰撞 yso构造分析: 首先构造进行rc ...

  8. BEM命名及其在sass中的实践

    Why use it 近几年web应用的发展可以用疯狂来形容,依靠浏览器的支持以及前端技术和框架的发展,很多应用已经把大量的逻辑从服务器端迁移到了浏览器端,使用前后端分离技术,浏览器端与用户进行交互来 ...

  9. String常见的方法有哪些?

    length();//计算字符串的长度 charAt();//截取一个字符 getChars();//截取多个字符 equals();//比较两个字符串 equalsIgnoreCase();//比较 ...

  10. Git的使用流程及常用命令汇总

    Git是一个很好用的版本控制系统,本文对于常用的一些命令进行了汇总. 创建一个存储仓库(repository) https://github.com/右上角点击"+"号,New r ...