Desciption

Consider a set of n points in a 2-D plane with integer coordinates. There are various ways of measuring distance between two points such as Euclidean , Manhattan , Chebyshev distance. These distances have important application , one of which is chess.

Consider that the ith point is located at (xi , yi). We want to find the number of pairs(i, j) such that the Euclidean distance between the points i and j is equal to the Manhattan distance between the same two points, i.e. Euclidean distance(i, j) = Manhattan distance(i, j).

√((xi − xj )^2 + (yi − yj )^2) - is called Euclidean distance

| xi − xj | + | yi − yj | - is called Manhattan distance

Note - All the n points given are considered different, even if they share the same coordinates.

Input

First line contains n, number of points in the plane Each of the following n lines contains two integers xi , yi

Output

Print the total number of such pairs.

Example

Input:
3
1 1
7 5
1 5

Output:
2
Input:
6
0 0
0 1
0 2
-1 1
0 1
1 1

Output:
11
解题思路:注意判断两个小数是否相等,一般采用作差法。如果两个小数的差值小于一个很小的精度,则视这两个小数相等。这题没给出n的范围,后台测试数据比较小,暴力O(n^2)水过。
AC代码:
 #include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e6+;
int n,m=;double x[maxn],y[maxn];
const double eps=1e-;
double Eulc(double a1,double b1,double a2,double b2){
return sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));
}
double Manh(double a1,double b1,double a2,double b2){
return abs(a1-a2)+abs(b1-b2);
}
int main(){
cin>>n;
for(int i=;i<n;++i)cin>>x[i]>>y[i];
for(int i=;i<n-;++i){
for(int j=i+;j<n;++j){
if(abs(Eulc(x[i],y[i],x[j],y[j])-Manh(x[i],y[i],x[j],y[j]))<eps)m++;
}
}
cout<<m<<endl;
return ;
}
 

Q - Euclid in Manhattan(欧几里德距离==曼哈顿距离?)的更多相关文章

  1. Hdu 4312-Meeting point-2 切比雪夫距离,曼哈顿距离,前缀和

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4312 Meeting point-2 Time Limit: 2000/1000 MS (Java/Ot ...

  2. BZOJ3170 [Tjoi2013]松鼠聚会 切比雪夫距离 - 曼哈顿距离 - 前缀和

    BZOJ3170 题意: 有N个小松鼠,它们的家用一个点x,y表示,两个点的距离定义为:点(x,y)和它周围的8个点即上下左右四个点和对角的四个点,距离为1.现在N个松鼠要走到一个松鼠家去,求走过的最 ...

  3. K-means真的不能使用曼哈顿距离吗?

    问题 说到k-means聚类算法,想必大家已经对它很熟悉了,它是基于距离计算的经典无监督算法,但是有一次在我接受面试时,面试官问了我一个问题:“k-means为什么不能使用曼哈顿距离计算,而使用欧式距 ...

  4. Atitti knn实现的具体四个距离算法 欧氏距离、余弦距离、汉明距离、曼哈顿距离

    Atitti knn实现的具体四个距离算法  欧氏距离.余弦距离.汉明距离.曼哈顿距离 1. Knn算法实质就是相似度的关系1 1.1. 文本相似度计算在信息检索.数据挖掘.机器翻译.文档复制检测等领 ...

  5. hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  6. HDU 4666 Hyperspace (最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  7. HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  8. 暴力三维树状数组求曼哈顿距离求最值——牛客多校第八场D

    涉及的知识点挺多,但是大多是套路 1.求曼哈顿距离的最值一般对所有情况进行讨论 2.三维树状数组用来求前缀最大值 /* 有一个三维坐标系(x,y,z),取值范围为[1,n],[1,m],[1,h],有 ...

  9. hdu4666 Hyperspace ——曼哈顿距离

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4666 这题学会了怎么处理曼哈顿距离. 比如维数是k,那么每个点有2^k个状态,求出在每个状态下,所有点 ...

随机推荐

  1. Floyd算法——保存路径——输出路径 HDU1385

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1385 参考 http://blog.csdn.net/shuangde800/article/deta ...

  2. cogs——1001. [WZOI2011 S3] 消息传递

    1001. [WZOI2011 S3] 消息传递 ★★   输入文件:messagew.in   输出文件:messagew.out   简单对比时间限制:1 s   内存限制:128 MB Prob ...

  3. docker容器-快速部署Jenkins

    1.在本地虚拟机环境.安装CentOS 7,并安装docker容器 2.在docker容器中执行  docker pull jenkinsci/blueocean 3.查看已经下载的Jenkins镜像 ...

  4. SLF4J 和 Logback 在 Maven 项目中的使用方法

    原文:http://blog.csdn.net/llmmll08/article/details/70217120 本文介绍 SLF4J 和 Logback 在 Maven 项目中的用法,包括日志框架 ...

  5. 模拟用户点击弹出新页面不会被浏览器拦截_javascript技巧

    原文:http://www.html5cn.com.cn/article/zxzx/3195.html 相信用过window.open的小伙伴们都遇到过被浏览器拦截导致页面无法弹出的情况:我们换下思路 ...

  6. Windows下安Mac

    Windows PC下安装苹果系统 第一步: 準備2個新邏輯分區,一個6G(os),一個隨意(Mac),且不要格式化. 第二步: 启动硬盘助手,选择下载好的苹果镜像文件  .再选择6G(os)分區,寫 ...

  7. Android内存泄露之开篇

    先来想这三个问题 内存泄露是怎么回事 内存会泄露的原因 避免内存泄露 1.内存泄露怎么回事 一个程序中,已经不须要使用某个对象,可是由于仍然有引用指向它垃圾回收器就无法回收它,当然该对象占用的内存就无 ...

  8. Binary Tree Maximum Path Sum 自底向上求解(重重重重)

    题目: 链接 解答: 自底向上求解.left_max right_max分别返回了左右子树的最大路径和,假设左右子树最大路径和小于0.那么返回零. 用这个最大路径和和根节点的值相加.来更新最大值,同一 ...

  9. 策略模式&反射

    业务代码 class Operate { public string _firstKey; public string _secondKey; public string _extendKey; pu ...

  10. 运行shell脚本报错 &#39;\357\273\277&#39;: command not found 解决的方法

    1,删除BOM,在vi以下运行以下的命令就可以 :set nobomb 2,原因: 所谓BOM,全称是Byte Order Mark.它是一个Unicode字符,通常出如今文本的开头,用来标识字节序( ...