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 ...
随机推荐
- ERROR 1839 (HY000): @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_MODE = ON
从cdb上dump一个库结构,准备与本地结构做对比(可以直接compare,但速度贼慢).使用dump脚本在本地创建的时候报错 -- 导出指定库的结构 shell> mysqldump -hxx ...
- echars前端处理数据、pyechars后端处理数据
echars -- 后端给数据,前端根据数据做渲染 - echarts:https://www.echartsjs.com/zh/index.htmlhtml文件 <!DOCTYPE html& ...
- Dubbo + Kryo 实现高速序列化
Dubbo 中的序列化 Dubbo RPC 是 Dubbo 体系中最核心的一种高性能.高吞吐量的远程调用方式,可以称之为多路复用的 TCP 长连接调用: 长连接:避免了每次调用新建 TCP 连接,提高 ...
- HTML - 表单标签相关
<html> <head></head> <body> <!-- 表单标签 : 收集其标签内部的数据, 提交给指定的服务器 action : 数据 ...
- AMPQ
AMPQ AMQP,即Advanced Message Queuing Protocol,高级消息队列协议, 是`应用层协议的一个开放标准,为面向消息的中间件设计`. 由于AMQP是一个网络协议,所以 ...
- string、char* 、int数据类型相互转换
string类型转换成char*类型,这里一般有以下三种方法: 1.c_str()方法 string name="Qian"; char *str=(char*)name.c_st ...
- Centos--swoole平滑重启服务
平滑重启: 已经打开的服务: 首先在server服务中为进程添加名字: /** * @param $server */ public function onStart($server) { swool ...
- zuul隔离机制
文章转载自:https://blog.csdn.net/farsight1/article/details/80078099 ZuulException REJECTED_SEMAPHORE_EXEC ...
- SPSS输出结果统计表与统计图的专业性编辑及三线表定制格式
SPSS输出结果统计表与统计图的专业性编辑及三线表定制格式 世界前三统计软件,SPSS最容易学习,但SPSS默认输出的统计表与统计图美观度与专业度不够好,离发表水平尚有距离,本期咱们就谈谈SPSS图表 ...
- Open CASCADE Technology: IGES Support
2015/6/4 Open CASCADE Technology: IGES Support http://www.opencascade.org/doc/occt6.7.0/overview/ht ...