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. loadrunner通过web的post请求方法测接口 1

    loadrunner通过web的post请求方法测接口 loginapi() {     web_url("rest",          "URL=http://192 ...

  2. iOS多线程开发之NSOperation

    一.什么是NSOperation? NSOperation是苹果提供的一套多线程解决方案.实际上NSOperation是基于GCD更高一层的封装,但是比GCD更加的面向对象.代码可读性更高.可控性更强 ...

  3. django--ajax的使用,应用

    Ajax简介 AJAX(Asynchronous Javascript And XML)翻译成中文就是“异步Javascript和XML”.即使用Javascript语言与服务器进行异步交互,传输的数 ...

  4. Jackie's blog

    介绍使用winmm.h进行音频流的获取   首先需要包含以下引用对象 #include <Windows.h>#include "mmsystem.h"#pragma ...

  5. STM32F103驱动ADS1118

    ADS1118 作为常用温度测量芯片被越来越多的开发者熟知,TI官方给出的是基于 MSP430 的驱动测试程序,由于 STM32 的普及,闲暇中移植了 MSP430 的 ADS1118 驱动程序到 S ...

  6. 【HI AI:人机协同 赋能未来系列】计算机是最好的左脑

    AI:人机协同 赋能未来系列]计算机是最好的左脑"> 编者按: 计算机领域的热点总是在不断更替,从大数据到云计算再到人工智能,这些热点的背后离不开专家学者们在这些领域一点一滴聚沙成塔的 ...

  7. 【原创】(三)Linux进程调度器-进程切换

    背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...

  8. Java工厂模式解耦 —— 理解Spring IOC

    Java工厂模式解耦 -- 理解Spring IOC 最近看到一个很好的思想来理解Spring IOC,故记录下来. 资源获取方式 主动式:(要什么资源都自己创建) 被动式:(资源的获取不是我们创建, ...

  9. java 初探-猜数字

    学习Java而编写的猜数字的程序代码. /** * */ package org.literal.test; import java.util.Scanner; /** * @author liter ...

  10. 并查集(不相交集)的Union操作

    在并查集(不相交集)中附加操作\(Deunion\),它实现的功能是取消最后一次\(Union\)的操作. 实现思想 初始化一个空栈,将每一次的\(Union\)操作的两个集合的根和其值\(Push\ ...