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. 错综复杂!“两桶油”与多个APP上演暧昧秀

    O2O的浪潮席卷了一个又一个行业,即使在资本寒冬下一批批O2O企业倒下,却总有另一批毫不犹豫地站起来.其中,汽车后服务市场就是被O2O台风重点扫过.洗车.保养.维修.美容.改装等相关O2O企业层出不穷 ...

  2. C++走向远洋——22(项目一,三角形,类)

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

  3. nvm安装以及注意事项

    nvm初衷:由于以后的开发工作可能会在多个Node版本中测试,而且Node的版本也比较多,所以需要这么款工具来管理 1. 下载:[nvm-windows](https://github.com/cor ...

  4. 有了这个开源 Java 项目,开发出炫酷的小游戏好像不难?

    本文适合有 Java 基础知识的人群,跟着本文可学习和运行 Java 的游戏. 本文作者:HelloGitHub-秦人 HelloGitHub 推出的<讲解开源项目>系列,今天给大家带来一 ...

  5. DIV的失去焦点(blur)实现

    用防抖实现DIV鼠标移出消失   由于div标签本身不支持onblur事件,所以对于点击一个按钮弹出的div,我们想要当这个div失去焦点的时候,让它消失不能使用的onblur来实现.  但是可以利用 ...

  6. DvaJS入门课

    不管是Vue还是React,他们都没解决组件间的通信和数据流问题.当然,这个说法不是很准确,准确的说法是他们都没很好的处理这些问题.我们是可以用一些烂手段去解决这个问题,但是当应用比较大.数据多的时候 ...

  7. echarts 图点击事件

    有三种方式,介绍一下,大家学习哈 1.利用tooltip记录信息,使用zr 监听事件,进行事件处理. 这种方法是利用showTip方法或者tooltip的formatter函数记录选中的数据信息,并在 ...

  8. JavaScript对象(三)

    序列化对象: 对象序列化:对象的状态转化为字符串,也可以将字符串还原为对象.方法:JSON.stringify(),用来序列化,JSON.parse(),用来还原对象. JSON(JavaScript ...

  9. 什么是容器,什么是Docker?

    此文转载自http://www.cnblogs.com/CloudMan6/p/6751516.html行文时有所改动 什么是容器?什么是Docker? 容器是一种轻量级.可移植.自包含的软件打包技术 ...

  10. vue中moment.js的使用

    一.介绍 moment.js是一款现在对时间处理的强大的函数. Moment被设计用于在浏览器和Node.js中工作. 目前ci系统使用的浏览器有:IE8.IE9在Windows 7上.Chrome在 ...