public class Solution
{
/// <summary>
/// 计算两个点的距离
/// </summary>
/// <param name="x1"></param>
/// <param name="y1"></param>
/// <param name="x2"></param>
/// <param name="y2"></param>
/// <returns></returns>
private double getDistance(int x1, int y1, int x2, int y2)
{
var dis = (y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1);
return dis;
} /// <summary>
/// 计算n的阶乘
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
private int SetpNum(int n)
{
int sum = ;
while (n != )
{
sum *= n;
n = n - ;
}
return sum;
} public int NumberOfBoomerangs(int[,] points)
{
var pointcount = points.GetLength();//点个数
var dim = points.GetLength();//每组个点的坐标维数
List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, int>>(); for (int i = ; i < pointcount; i++)
{
var point = new KeyValuePair<int, int>(points[i, ], points[i, ]);
list.Add(point);
} //var dic = new Dictionary<KeyValuePair<int, int>, Dictionary<double, List<KeyValuePair<int, int>>>>();
var dic = new Dictionary<KeyValuePair<int, int>, Dictionary<double, int>>(); for (int i = ; i < list.Count; i++)
{
for (int j = i; j < list.Count; j++)
{
if (i != j)
{
var curentPoint = list[i];//主点
var otherPoint = list[j];//从点 var dis = getDistance(list[i].Key, list[i].Value, list[j].Key, list[j].Value);//dis值是同一个 #region 主点处理
if (!dic.ContainsKey(curentPoint))
{
//dic.Add(curentPoint, new Dictionary<double, List<KeyValuePair<int, int>>>());
//dic[curentPoint].Add(dis, new List<KeyValuePair<int, int>>());
//dic[curentPoint][dis].Add(list[j]); dic.Add(curentPoint, new Dictionary<double, int>());
dic[curentPoint].Add(dis, );
}
else
{
if (!dic[curentPoint].ContainsKey(dis))
{
//dic[curentPoint].Add(dis, new List<KeyValuePair<int, int>>());
//dic[curentPoint][dis].Add(list[j]); dic[curentPoint].Add(dis, );
}
else
{
//dic[curentPoint][dis].Add(list[j]); dic[curentPoint][dis]++;
}
}
#endregion 主点处理 #region 从点处理
if (!dic.ContainsKey(otherPoint))
{
//dic.Add(otherPoint, new Dictionary<double, List<KeyValuePair<int, int>>>());
//dic[otherPoint].Add(dis, new List<KeyValuePair<int, int>>());
//dic[otherPoint][dis].Add(list[i]); dic.Add(otherPoint, new Dictionary<double, int>());
dic[otherPoint].Add(dis, );
}
else
{
if (!dic[otherPoint].ContainsKey(dis))
{
//dic[otherPoint].Add(dis, new List<KeyValuePair<int, int>>());
//dic[otherPoint][dis].Add(list[i]); dic[otherPoint].Add(dis, );
}
else
{
//dic[otherPoint][dis].Add(list[i]); dic[otherPoint][dis]++;
}
} #endregion 从点处理
}
}
} var sum = ; foreach (var d in dic)
{
foreach (var d2 in d.Value)
{
if (d2.Value > )
{
var ct = d2.Value;
//计算从Count中任取2个的排列数即A(count)(2)
sum += ct * (ct - );
}
}
} return sum;
}
}

https://leetcode.com/problems/number-of-boomerangs/#/description

leetcode447的更多相关文章

  1. [Swift]LeetCode447. 回旋镖的数量 | Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  2. LeetCode447. Number of Boomerangs

    Description Given n points in the plane that are all pairwise distinct, a "boomerang" is a ...

  3. Leetcode447.Number of Boomerangs回旋镖的数量

    给定平面上 n 对不同的点,"回旋镖" 是由点表示的元组 (i, j, k) ,其中 i 和 j 之间的距离和 i 和 k 之间的距离相等(需要考虑元组的顺序). 找到所有回旋镖的 ...

随机推荐

  1. 【liunx】端口号的占用情况查看

    Linux如何查看端口 1.lsof -i:端口号 用于查看某一端口的占用情况,比如查看8000端口使用情况,lsof -i:8000 # lsof -i:8000 COMMAND PID USER ...

  2. ory Oathkeeper docker-compose 安装运行

    Oathkeeper 相关介绍可以参考官方文档,主要就是cloud native 身份以及访问代理 运行环境使用docker 安装(api proxy ) Dockerfile api: docker ...

  3. centos 使用mutt发送邮件带附件

    1.安装mutt工具 yum install -y mutt 2.使用mutt发邮件并带附件echo "统计日志" | /usr/bin/mutt -s "统计日志&qu ...

  4. NOI2002银河英雄传说——带权并查集

    题目:https://www.luogu.org/problemnew/show/P1196 关键点在于存下每个点的位置. 自己糊涂的地方:位置是相对于谁的位置? 因为每次给一个原来是fa的点赋位置时 ...

  5. <<精通正在表达式>> 书评

     IT产业新技术日新月异,令人目不暇给,然而在这其中,真正称得上伟大东西的却寥寥无几.1998年,被誉为“软件世界的爱迪生”,发明了BSD. TCP/IP.csh.vi和NFS的SUN首席科学家Bil ...

  6. BASIC-18_蓝桥杯_矩形面积交

    解题思路: 1.先将可能的情况列出,根据分类确定计算的方式; 示例代码: #include <stdio.h>#define N 8 int main(void){ int i = 0 , ...

  7. 【Ethereum】以太坊ERC20 Token标准完整说明

    什么是ERC20 token 市面上出现了大量的用ETH做的代币,他们都遵守REC20协议,那么我们需要知道什么是REC20协议. 概述 token代表数字资产,具有价值,但是并不是都符合特定的规范. ...

  8. python random 随机选择操作

    # -*- coding:utf-8 -*- import random arr = ['A','B','C','D','E','F'] #生成(0.0, 1.0)的随机数 print random. ...

  9. 退出循环break,在while、for、do...while、循环中使用break语句退出当前循环,直接执行后面的代码。

    在while.for.do...while循环中使用break语句退出当前循环,直接执行后面的代码. 格式如下: for(初始条件;判断条件;循环后条件值更新) { if(特殊情况) {break;} ...

  10. matplot 代码实例

    matplot 代码实例 #!/usr/bin/env python # coding=utf-8 import numpy as np import matplotlib.pyplot as plt ...