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 ...
随机推荐
- 再谈OpenCV
虽然之前写过一篇关于OpenCV的介绍(http://blog.csdn.net/carson2005/article/details/5822149).但依旧有朋友对其不甚了解.所以,常常能碰到有人 ...
- map集合排序
默认情况下,HashMap.HashTable.TreeMap.LinkedHashMap的排列顺序比较: package com.per.sdg.demo; import java.util.Has ...
- QC ALM 11创建域、项目和用户
一旦HP-ALM安装,我们仅仅能继续创建域.项目和用户使用后的ALM工作.以下是步骤来创建项目.域和用户. 一.创建域 1.对于创建域,第一步是进入站点管理员页面.开展QC使用URL - ...
- 使用变量作为js对象的属性名
<script> var test={aa:12,bb:34};//或者var test={}; var cc= "acqId" test[cc]=12; alert( ...
- 使用scanf_s报错:0xC0000005: Access violation writing location 0x00000000
在vs2010中写了一行scanf("%s",name); 调式时 提示warning , 提示修改为scanf()使用可能会存在不安全,建议使用scanf_s() 但是我修改成s ...
- YTU 2596: 编程题B-日期格式
2596: 编程题B-日期格式 时间限制: 1 Sec 内存限制: 128 MB 提交: 981 解决: 74 题目描述 注:本题只需要提交编写的函数部分的代码即可. 将输入的日期格式 月/日/年 ...
- 虚拟机C盘扩容
使用 <分区助手> 下载地址:http://115.com/file/belj8wkm
- 视图表单访问控制器操作方法的POST、GET方式对应关系
在视图中,表单默认访问方式是FormMethod.Post(不会将请求显示在地址栏中).在控制器中,操作方法不标注属性,默认为HttpGet属性.会有以下情况出现. 1.表单不指定访问方式(默认形式为 ...
- 摘抄 - linux 目录结构简介
/ 根目录 |—–/bin 软连接,指向 /usr/bin.存储一些命令,一般为用户命令 |—-/boot 系统启动相关的文件;包括启动时内核的一些配置,grub配置等等:一般为之分配300 ...
- Gym 100531J Joy of Flight (几何)
题意:你从开始坐标到末尾坐标,要经过 k 秒,然后给你每秒的风向,和飞机的最大速度,问能不能从开始到末尾. 析:首先这个风向是不确定的,所以我们先排除风向的影响,然后算出,静风是的最小速度,如果这都大 ...