给定平面上 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]]
详见:https://leetcode.com/problems/number-of-boomerangs/description/

C++:

class Solution {
public:
int numberOfBoomerangs(vector<pair<int, int>>& points)
{
int res = 0;
for (int i = 0; i < points.size(); ++i)
{
unordered_map<int, int> m;
for (int j = 0; j < points.size(); ++j)
{
int a = points[i].first - points[j].first;
int b = points[i].second - points[j].second;
++m[a * a + b * b];
}
for (auto it = m.begin(); it != m.end(); ++it)
{
res += it->second * (it->second - 1);
}
}
return res;
}
};

参考:https://leetcode.com/problems/number-of-boomerangs/description/

447 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. Leetcode447.Number of Boomerangs回旋镖的数量

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

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

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

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

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

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

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

  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. 34. leetcode 447. Number of Boomerangs

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

  8. 447. Number of Boomerangs

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

  9. [LeetCode&Python] Problem 447. Number of Boomerangs

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

随机推荐

  1. Android使用am命令实现拨打电话、打开应用

    前提: 在Android 通话自己主动化測试中会用到am命令去拨打电话.打开音乐播放器播放音乐等等操作. 这里总结一下am命令. Android am命令: (1)命令參数: am start -n ...

  2. Mongodb for PHP教程之管理工具

    1:下面的事情应该是PHP程序员应该了解的,更详细的参考可以百度谷歌之 mongodb PHP官方文档http://us.php.net/manual/en/book.mongo.php 1.Mong ...

  3. 2016/04/13 ①html 中各种分割线------------------------------------------ ② 控制文字显示

    ①各种分割线Html代码 1.<HR> 2.<HR align=center width=300 color=#987cb9 SIZE=1>align 线条位置(可选left. ...

  4. jupyter环境的安装

    1,什么是jupyter notebook? 简介:jupyter notebook是基于网页的用户交互计算机的应用程序,其可被用于全过程计算:开发,文档编写,运行代码,和展示结果 简而言之,Jupy ...

  5. What Is the Linux Lokkit Utility? https://www.lifewire.com/what-is-lokkit-2192255

    lokkit: The Lokkit utility attempts to provide firewalling for the average Linux end user. Instead o ...

  6. Bootstrap + Font Awesome

    将Font Awesome 集成到 Bootstrap 非常容易,还可以被单独使用. 最简单的 Bootstrap + Font Awesome 集成方式 使用这种方式将 Font Awesome 集 ...

  7. [原创]java导出word的5种方式

    在网上找了好多天将数据库中信息导出到word中的解决方案,现在将这几天的总结分享一下.总的来说,java导出word大致有5种解决方案: 1:Jacob是Java-COM Bridge的缩写,它在Ja ...

  8. 关于kafka-clients JAVA API的基本使用

    首先老规矩, 引入maven依赖 <dependency> <groupId>org.apache.kafka</groupId> <artifactId&g ...

  9. Pow(x, n) 位运算总结 典型

    https://leetcode.com/problems/powx-n/ Implement pow(x, n), which calculates x raised to the power n  ...

  10. winform 自动升级

    自动升级系统OAUS的设计与实现(续) (附最新源码) http://www.cnblogs.com/zhuweisky/p/4209058.html Winform在线更新 http://www.c ...