Leetcode447.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]]
暴力:
class Solution {
public:
int Distance(int x1, int x2, int y1, int y2)
{
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
int numberOfBoomerangs(vector<pair<int, int>>& points)
{
int cnt = 0;
int len = points.size();
for (int i = 0; i < len - 2; i++)
{
for (int j = i + 1; j < len - 1; j++)
{
for (int k = j + 1; k < len; k++)
{
if (Distance(points[i].first, points[j].first, points[i].second, points[j].second) ==
Distance(points[i].first, points[k].first, points[i].second, points[k].second))
cnt++;
if (Distance(points[j].first, points[i].first, points[j].second, points[i].second) ==
Distance(points[j].first, points[k].first, points[j].second, points[k].second))
cnt++;
if (Distance(points[k].first, points[i].first, points[k].second, points[i].second) ==
Distance(points[k].first, points[j].first, points[k].second, points[j].second))
cnt++;
}
}
}
return cnt * 2;
}
};
Leetcode447.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 ...
- 447 Number of Boomerangs 回旋镖的数量
给定平面上 n 对不同的点,“回旋镖” 是由点表示的元组 (i, j, k) ,其中 i 和 j 之间的距离和 i 和 k 之间的距离相等(需要考虑元组的顺序).找到所有回旋镖的数量.你可以假设 n ...
- LeetCode447. Number of Boomerangs
Description Given n points in the plane that are all pairwise distinct, a "boomerang" is a ...
- [Swift]LeetCode447. 回旋镖的数量 | Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- C#LeetCode刷题之#447-回旋镖的数量(Number of Boomerangs)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3792 访问. 给定平面上 n 对不同的点,"回旋镖&q ...
- 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 ...
随机推荐
- Loadrunner 性能测试工具笔记
性能的是的基础知识 什么是负载? 系统实际用户:可能会有很多人使用同一个系统,但并不是所有用户都回同时使用该系统,所以系统的实际用户是一个容量问题,而不是负载的问题 系统在线用户:当系统用户对系统进行 ...
- Python调用DLL动态链接库——ctypes使用
最近要使用python调用C++编译生成的DLL动态链接库,因此学习了一下ctypes库的基本使用. ctypes是一个用于Python的外部函数库,它提供C兼容的数据类型,并允许在DLL或共享库中调 ...
- Node中的模块系统
加载require var 自定义变量名称 = require('模块') 两个作用: 执行被加载模块的代码 得到被加载模块中的exports导出接口对象 导出exports node中是模块作用域, ...
- [violet6] 故乡的梦
题目 描述 不知每日疲于在城市的水泥森林里奔波的你会不会有时也曾向往过乡村的生活.你会不会幻想过,在夏日一个静谧的午后,你沉睡于乡间路边的树荫里,一片叶子落在了你的肩上, 而你正做着一个悠长的梦,一个 ...
- 用C++Builder在Windows开始按钮上绘图制作方法
熟悉Windows操作系统的软件设计人员知道,在Win95/98/NT/2000中有一任务栏(Task Bar)程序,路径为:C:\WINDOWS\SYSTEM\SYSTRAY.EXE(假设你的Win ...
- laravel框架中使用QueryList插件采集数据
laravel框架中使用queryList 采集数据 采集数据对我们来说真家常便饭,那么苦苦的写正则采集那么一点点东西,花费了自己大把的时间和精力而且没有一点技术含量,这个时候就是使用我们的好搭档Qu ...
- Android之相关术语
Dalvik: Android特有的虚拟机,和JVM不同,Dalvik虚拟机非常适合在移动终端上使用! AVD: (android virtual machine):安卓虚拟设备,就是安卓的模拟器 A ...
- PAT甲级——A1001A+BFormat
Calculate a+b and output the sum in standard format -- that is, the digits must be separated into gr ...
- DOS批处理脚本
先概述一下批处理是个什么东东.批处理的定义,至今我也没能给出一个合适的----众多高手们也都没给出----反正我不知道----看了我也不一定信服----我是个菜鸟,当然就更不用说了:但我想总结出一个“ ...
- VIsualSVN server 安装及旧仓库导入
安装参考: 1, http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html SVN服务器搭建和使用(一) Subversi ...