2020-02-10 21:02:13

问题描述:

问题求解:

本题由于可以暴力求解,所以不是特别难,主要是用来熟悉计算几何的一些知识点的。

  1. public double minAreaFreeRect(int[][] points) {
  2. double res = 2e9;
  3. Map<Integer, Set<Integer>> record = new HashMap<>();
  4. for (int[] p : points) {
  5. int x = p[0];
  6. int y = p[1];
  7. if (!record.containsKey(x)) record.put(x, new HashSet<>());
  8. record.get(x).add(y);
  9. }
  10. int n = points.length;
  11. for (int i = 0; i < n; i++) {
  12. for (int j = i + 1; j < n; j++) {
  13. for (int k = j + 1; k < n; k++) {
  14. 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])) {
  15. res = Math.min(res, area(points[i], points[j], points[k]));
  16. }
  17. }
  18. }
  19. }
  20. return res == 2e9 ? 0 : res;
  21. }
  22.  
  23. private boolean check(int[] p1, int[] p2, int[] p3) {
  24. return (p2[0] - p1[0]) * (p3[0] - p1[0]) + (p2[1] - p1[1]) * (p3[1] - p1[1]) == 0;
  25. }
  26.  
  27. private double area(int[] p1, int[] p2, int[] p3) {
  28. return Math.abs(p1[0] * p2[1] + p1[1] * p3[0] + p2[0] * p3[1] -
  29. p2[1] * p3[0] - p1[1] * p2[0] - p1[0] * p3[1]);
  30. }

  

计算几何-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. fabric 初步实践

    在集群部署时,我们经常用到堡垒机作为跳板,堡垒机和集群的其他的用户名.密码.端口号都是不同的,fabric如何进行配置不同的用户.端口号和密码. fabric作为一种强大的运维工具,可以让部署运维轻松 ...

  2. JVM性能优化系列-(7) 深入了解性能优化

    7. 深入了解性能优化 7.1 影响系统性能的方方面面 影响系统性能的因素有很多,以下列举了常见的一些系统性能优化的方向: 7.2 常用的性能评价和测试指标 响应时间 提交请求和返回该请求的响应之间使 ...

  3. 02ARM体系结构

    1.哈佛结构和冯式结构 8086: 冯氏结构 相同存储RAM相同的通道 统一编址 区别:运行态与存储态 STM32F103:哈弗结构 不同的存储不同的通道  统一编址 8051: 改进型的哈弗结构 不 ...

  4. 7-12 产生每位数字相同的n位数 (30 分)

    读入2个正整数A和B,1<=A<=9, 1<=B<=10,产生数字AA...A,一共B个A 输入格式: 在一行中输入A和B. 输出格式: 在一行中输出整数AA...A,一共B个 ...

  5. 不要写很酷但同事看不懂的Java代码

    你好呀,我是沉默王二,一个和黄家驹一样身高,和刘德华一样颜值的程序员.为了提高 Java 编程的技艺,我最近在 GitHub 上学习一些高手编写的代码.下面这一行代码(出自大牛之手)据说可以征服你的朋 ...

  6. psql的时间类型,通过时间查询

    psql的时间类型,通过时间查询 psql有date/timestamp类型,date只显示年月日1999-01-08,而timestamp显示年月日时分秒 1999-01-08 09:54:03.2 ...

  7. Codeforces Round #292 (Div. 2) C. Drazil and Factorial 515C

    C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. Tomcat8优化--Apache JMeter测试

    一.部署测试java web项目(压力测试环境搭建) 1.mysql环境 #切换到mysql目录 cd /usr/local/mysql #查看mysql环境 rpm -qa | grep -i my ...

  9. webpack进阶(二)

    1)webpack动态打包所有依赖项,避免打包未使用的模块. 2)转换css的loader有:css-loader,style-loader,加载图片或文件的loader是:file-loader,如 ...

  10. python字符串的常见操作

    find: 根据指定字符串获取对应的下标, 如果找不到对应的数据返回-1, 这里的-1表示没有找到数据 my_str = "hello" # find: 根据指定字符串获取对应的下 ...