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. Network(poj 3694)

    题意:一个无向图可以有重边,下面q个操作,每次在两个点间连接一条有向边,每次连接后整个无向图还剩下多少桥(注意是要考虑之前连了的边,每次回答是在上一次的基础之上) /* tarjan+LCA 先用ta ...

  2. 【NOIP2017练习】溢出(模拟)

    题意: 思路: a*b<=c <====> b<=c div a var ch,maxs,s:ansistring; v,k,i,maxl,l,len,cnt,cas:long ...

  3. Same Tree (二叉树DFS)

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  4. springboot 子模块访问不到对应的页面

    出现如下错误 解决方案 working directory:没有$MODULE_DIR$该选项,自己输入即可. 完成以上操作就可以正常访问页面了.

  5. zabbix学习系列之QQ消息报警

    安装依赖包 环境 Zabbix: 3.2 OS:Centos 安装依赖包 yum install lrzsz chrony gcc gcc-c++ git openssl-devel perl-Ext ...

  6. Redis官网下载步骤(含windows版)

    ①.百度redis ,进入官网 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  7. Linux下完美使用find+grep实现全局代码搜索

    作者:zhanhailiang 日期:2014-10-11 背景 在Window下有大量方便的图形化工具能够实现全局搜索,可是Linuxserver中因为使用命令行操作导致全局搜索是一个比較高的门槛. ...

  8. C++中使用Json的方法

    使用 C++ 处理 JSON 数据交换格式 一.摘要 JSON 的全称为:JavaScript Object Notation,顾名思义,JSON 是用于标记 Javascript 对象的,JSON官 ...

  9. Node.js创建自签名的HTTPS服务器

    https://cnodejs.org/topic/54745ac22804a0997d38b32d  用Node.js创建自签名的HTTPS服务器  发布于 4 年前  作者 eeandrew  6 ...

  10. Codeforces Round #313 B. Gerald is into Art(简单题)

    B. Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standa ...