博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
447. Number of Boomerangs
阅读量:4655 次
发布时间:2019-06-09

本文共 1175 字,大约阅读时间需要 3 分钟。

Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals the distance between i and k (the order of the tuple matters).

Find the number of boomerangs. You may assume that n will be at most 500 and coordinates of points are all in the range [-10000, 10000] (inclusive).

Example:

Input:[[0,0],[1,0],[2,0]]Output:2Explanation:The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]] 给3个点,计算1个点到另外两个点都相等有多少种组合 hypot(x,y)   计算 x 与 y 平方和的平方根 C++(386ms):
1 class Solution { 2 public: 3     int numberOfBoomerangs(vector
>& points) { 4 int res = 0; 5 unordered_map
ctr(points.size()); 6 for (auto p : points) { 7 for (auto q : points){ 8 if (p == q) 9 continue ;10 double t = hypot(p.first - q.first, p.second - q.second) ;11 ctr[t]++ ;12 res += 2 * (ctr[t]-1);13 }14 ctr.clear() ;15 }16 return res;17 }18 };

 

 

转载于:https://www.cnblogs.com/mengchunchen/p/7921686.html

你可能感兴趣的文章
使用Struts2标签遍历集合
查看>>
angular.isUndefined()
查看>>
第一次软件工程作业(改进版)
查看>>
网络流24题-飞行员配对方案问题
查看>>
Jenkins 2.16.3默认没有Launch agent via Java Web Start,如何配置使用
查看>>
引入css的四种方式
查看>>
iOS开发UI篇—transframe属性(形变)
查看>>
3月7日 ArrayList集合
查看>>
jsp 环境配置记录
查看>>
Python03
查看>>
LOJ 2537 「PKUWC2018」Minimax
查看>>
使用java中replaceAll方法替换字符串中的反斜杠
查看>>
Some configure
查看>>
流量调整和限流技术 【转载】
查看>>
1 线性空间
查看>>
VS不显示最近打开的项目
查看>>
DP(动态规划)
查看>>
chkconfig
查看>>
2.抽取代码(BaseActivity)
查看>>
夏天过去了, 姥爷推荐几套来自smashingmagzine的超棒秋天主题壁纸
查看>>