计算几何-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 ...
随机推荐
- fabric 初步实践
在集群部署时,我们经常用到堡垒机作为跳板,堡垒机和集群的其他的用户名.密码.端口号都是不同的,fabric如何进行配置不同的用户.端口号和密码. fabric作为一种强大的运维工具,可以让部署运维轻松 ...
- JVM性能优化系列-(7) 深入了解性能优化
7. 深入了解性能优化 7.1 影响系统性能的方方面面 影响系统性能的因素有很多,以下列举了常见的一些系统性能优化的方向: 7.2 常用的性能评价和测试指标 响应时间 提交请求和返回该请求的响应之间使 ...
- 02ARM体系结构
1.哈佛结构和冯式结构 8086: 冯氏结构 相同存储RAM相同的通道 统一编址 区别:运行态与存储态 STM32F103:哈弗结构 不同的存储不同的通道 统一编址 8051: 改进型的哈弗结构 不 ...
- 7-12 产生每位数字相同的n位数 (30 分)
读入2个正整数A和B,1<=A<=9, 1<=B<=10,产生数字AA...A,一共B个A 输入格式: 在一行中输入A和B. 输出格式: 在一行中输出整数AA...A,一共B个 ...
- 不要写很酷但同事看不懂的Java代码
你好呀,我是沉默王二,一个和黄家驹一样身高,和刘德华一样颜值的程序员.为了提高 Java 编程的技艺,我最近在 GitHub 上学习一些高手编写的代码.下面这一行代码(出自大牛之手)据说可以征服你的朋 ...
- psql的时间类型,通过时间查询
psql的时间类型,通过时间查询 psql有date/timestamp类型,date只显示年月日1999-01-08,而timestamp显示年月日时分秒 1999-01-08 09:54:03.2 ...
- 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 ...
- Tomcat8优化--Apache JMeter测试
一.部署测试java web项目(压力测试环境搭建) 1.mysql环境 #切换到mysql目录 cd /usr/local/mysql #查看mysql环境 rpm -qa | grep -i my ...
- webpack进阶(二)
1)webpack动态打包所有依赖项,避免打包未使用的模块. 2)转换css的loader有:css-loader,style-loader,加载图片或文件的loader是:file-loader,如 ...
- python字符串的常见操作
find: 根据指定字符串获取对应的下标, 如果找不到对应的数据返回-1, 这里的-1表示没有找到数据 my_str = "hello" # find: 根据指定字符串获取对应的下 ...