给定平面上 n 对不同的点,“回旋镖” 是由点表示的元组 (i, j, k) ,其中 i 和 j 之间的距离和 i 和 k 之间的距离相等(需要考虑元组的顺序)。

找到所有回旋镖的数量。你可以假设 n 最大为 500,所有点的坐标在闭区间 [-10000, 10000] 中。

示例:

输入: [[0,0],[1,0],[2,0]] 输出: 2 解释: 两个回旋镖为 [[1,0],[0,0],[2,0]] 和 [[1,0],[2,0],[0,0]]

暴力:

class Solution {
public:
int Distance(int x1, int x2, int y1, int y2)
{
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
} int numberOfBoomerangs(vector<pair<int, int>>& points)
{
int cnt = 0;
int len = points.size();
for (int i = 0; i < len - 2; i++)
{
for (int j = i + 1; j < len - 1; j++)
{
for (int k = j + 1; k < len; k++)
{
if (Distance(points[i].first, points[j].first, points[i].second, points[j].second) ==
Distance(points[i].first, points[k].first, points[i].second, points[k].second))
cnt++;
if (Distance(points[j].first, points[i].first, points[j].second, points[i].second) ==
Distance(points[j].first, points[k].first, points[j].second, points[k].second))
cnt++;
if (Distance(points[k].first, points[i].first, points[k].second, points[i].second) ==
Distance(points[k].first, points[j].first, points[k].second, points[j].second))
cnt++;
}
}
}
return cnt * 2;
}
};

Leetcode447.Number of Boomerangs回旋镖的数量的更多相关文章

  1. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  2. 447 Number of Boomerangs 回旋镖的数量

    给定平面上 n 对不同的点,“回旋镖” 是由点表示的元组 (i, j, k) ,其中 i 和 j 之间的距离和 i 和 k 之间的距离相等(需要考虑元组的顺序).找到所有回旋镖的数量.你可以假设 n ...

  3. LeetCode447. Number of Boomerangs

    Description Given n points in the plane that are all pairwise distinct, a "boomerang" is a ...

  4. [Swift]LeetCode447. 回旋镖的数量 | Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  5. C#LeetCode刷题之#447-回旋镖的数量(Number of Boomerangs)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3792 访问. 给定平面上 n 对不同的点,"回旋镖&q ...

  6. LeetCode 447. Number of Boomerangs (回力标的数量)

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  7. 447. Number of Boomerangs 回力镖数组的数量

    [抄题]: Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple ...

  8. 【LeetCode】447. Number of Boomerangs 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...

  9. [LeetCode]447 Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

随机推荐

  1. 【LGP5350】序列

    题目 可能\(\operatorname{fhq\ treap}\)能做,但是珂朵莉树显然更好写 珂朵莉树是个很玄学的东西啊,就是直接使用\(\operatorname{std::set}\)维护每一 ...

  2. 面试系列24 dubbo负载均衡策略和集群容错策略

    (1)dubbo负载均衡策略 1)random loadbalance 默认情况下,dubbo是random load balance随机调用实现负载均衡,可以对provider不同实例设置不同的权重 ...

  3. 基本包装类型Boolean、Number、String特性及常用方法

    基本包装类型:Boolean.Number.String 一.String 字符串常用方法 1.indexOf()  lastIndexOf()  返回相应字符的索引号 2.slice(index1, ...

  4. RPM包安装MySQL 5.7.18

    系统: CentOS 7 RPM包: mysql-community-client-5.7.18-1.el7.x86_64.rpm mysql-community-server-5.7.18-1.el ...

  5. Java jmx的使用

    JMX Java Management Extensions,Java管理扩展.本质就是用来监控java语言开发的程序,一般常用于jconsole,java visual VM的监控,今天主要介绍ja ...

  6. 自然数幂求和——第二类Strling数

    这个问题似乎有很多种求法,但感觉上第二类Strling数的做法是最方便的. 问题 求下面这个式子: ∑i=0nik\sum_{i=0}^n i^ki=0∑n​ik nnn的范围可以很大. 第二类Str ...

  7. window 下mongodb 配置

    1.下载mongodb-win32-x86_64-2008plus-ssl-v3.6-latest 解压到 D:\mongodb 2.cmd => path是否有环境变量 如果没有请配置 3.创 ...

  8. C# GDI+编程(二)

    常用的绘图函数 DrawArc绘制一个弧形 示例:graphics.DrawArc(pen,,,,,,) 倒数第二个参数,表示起始度数,最后一个参数是弧形的跨越度数.比如起始度数是90,跨越度数是12 ...

  9. Spring Boot使用Swagger2

    1.添加Swagger2依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>spri ...

  10. 在scrapy中将数据保存到mongodb中

    利用item pipeline可以实现将数据存入数据库的操作,可以创建一个关于数据库的item pipeline 需要在类属性中定义两个常量 DB_URL:数据库的URL地址 DB_NAME:数据库的 ...