447 Number of Boomerangs 回旋镖的数量
给定平面上 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 回旋镖的数量的更多相关文章
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- Leetcode447.Number of Boomerangs回旋镖的数量
给定平面上 n 对不同的点,"回旋镖" 是由点表示的元组 (i, j, k) ,其中 i 和 j 之间的距离和 i 和 k 之间的距离相等(需要考虑元组的顺序). 找到所有回旋镖的 ...
- LeetCode 447. Number of Boomerangs (回力标的数量)
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- 447. Number of Boomerangs 回力镖数组的数量
[抄题]: Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple ...
- 【LeetCode】447. Number of Boomerangs 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...
- [LeetCode]447 Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- 34. leetcode 447. Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- 447. Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- [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 ...
随机推荐
- SQL FULL OUTER JOIN 关键字
SQL FULL OUTER JOIN 关键字 SQL FULL OUTER JOIN 关键字 FULL OUTER JOIN 关键字只要左表(table1)和右表(table2)其中一个表中存在匹配 ...
- 理解Android ANR的触发原理(转)
一.概述 ANR(Application Not responding),是指应用程序未响应,Android系统对于一些事件需要在一定的时间范围内完成,如果超过预定时间能未能得到有效响应或者响应时间过 ...
- Hibernate学习(1)简单介绍
1.什么是Hibernate? 首先,Hibernate是数据持久层的一个轻量级框架.数据持久层的框架有非常多比方:iBATIS,myBatis,Nhibernate,Siena等 ...
- JavaScript-创建第一个自己的类库
通过上一节面向对象和原型的学习. 我们知道了怎样创建一个类,包含类的私有化属性和方法.公有化属性和方法.静态属性和方法.在这里略微回想一下.首先要创建一个类能够通过1.new object().2.利 ...
- 另外几种Java集合框架具体解释续
另外几种Java集合框架具体解释续 作者:chszs,未经博主同意不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs fastutil库优于Trove库的 ...
- Part1-Redefining your data-access strategy 重新定义你的数据访问策略
欢迎来到Entity Framework 4 In Action,EF是微软3.5 SP1推出的ORM工具,现在已经更新到4.0版本(...)本书能确保你in a robust and model- ...
- 两大数相乘 -- javascript 实现
(function (){ var addLarge = function(n1,n2){ var carry = 0; var ret = ""; n1=n1.toString( ...
- Oracle - 数据更新 - 增删改
/* 数据的更新 增加 删除 修改 */ -----------------------------------增加(一次只能插入一条数据) --自定义插入数据列的顺序 ,,); --按照数据库默认的 ...
- 运算符:三目运算符,运算符优先级,sizeof,自增自减,取余
一://---------运算符-----------// 1.运算符是告诉编译程序执行特定算术或逻辑操作的符号. 2.按照功能划分: 算术运算符. 关系运算符与逻辑运算符.按位运算符. 3.运算符根 ...
- 并不对劲的bzoj3529:loj2193:p3312:[SDOI2014]数表
题目大意 定义函数\(f(x)=\sum_{k|x}k\) \(t\)(\(t\leq2*10^4\))组询问,每组给定\(n,m,a\)(\(n,m\leq10^5,a\leq10^9\)),求: ...