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 ...
随机推荐
- PDO防止SQL注入具体介绍
<span style="font-size:18px;"><?php $dbh = new PDO("mysql:host=localhost; db ...
- random模块的使用
random模块用于生成随机数 import random print random.random() #用于生成小于1大于0的数 print random.randint(1,5) #生成大于等于1 ...
- .net面试整理
NET程序员的层次:http://blog.csdn.net/dinglang_2009/article/details/6913852 .NET牛人应该知道些什么http://www.douban. ...
- 数据结构与算法问题 AVL二叉平衡树
AVL树是带有平衡条件的二叉查找树. 这个平衡条件必须保持,并且它必须保证树的深度是O(logN). 一棵AVL树是其每一个节点的左子树和右子树的高度最多差1的二叉查找树. (空树的高度定义为-1). ...
- VTMagic的使用
// VTMagic的使用 // CFOrderViewController.m // qifuyuniOS //// /** * @author 李洪强, 16-08-30 10:08:50 ...
- 【iOS系列】-UITableView的使用
UITableView的使用: 第一:数据展示条件 1,UITableView的所有数据都是由数据源(dataSource)提供,所以想在UITableView展示数据,必须设置UITableview ...
- JS基本特效 -- 常见40个常用的js页面效果图(转载)
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键 <table border oncontextmenu ...
- JSON使用总结
参考网站 官网: http://www.json.org/ 菜鸟教程:http://www.runoob.com/json/json-tutorial.html 什么是 JSON ? JSON 指的是 ...
- 聚合类新闻client初体验
初体验的产品:今日头条(ios3.6).百度新闻(ios4.4.0).ZAKER(ios4.4.5).鲜果(ios3.8.7).中搜搜悦(ios4.0.1).Flipboard(ios2.3.9) 1 ...
- 设计模式-(10)观察者模式 (swift版)
一,概念 观察者(Observer)模式又名发布-订阅(Publish/Subscribe)模式.GOF给观察者模式如下定义:定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它 ...