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 ;
}
 

最新文章

  1. Qt4.8.5在ARM9上的移植
  2. IDL数组计算
  3. js 滚动 学习
  4. linux关于文件的那些事儿
  5. 猿题库 iOS 客户端架构设计
  6. python第十二天-----RabbitMQ
  7. php_curl.dll libssh2.dll 始终无法加载的原因 及解决办法
  8. Web Api2 用户认证模板解析---本地用户
  9. gulp入门
  10. cf C. Sereja and Algorithm
  11. oracle中clob字段的使用
  12. BZOJ 1609: [Usaco2008 Feb]Eating Together麻烦的聚餐
  13. php 利用Gd库添加文字水印乱码的问题及解决方案
  14. python拼接multipart/form-data类型post请求格式
  15. BootStrap小知识随笔
  16. EF(EntityFramework)与mysql使用,取数据报错,linq实体映射错误
  17. Python爬虫html解析工具beautifulSoup在pycharm中安装及失败的解决办法
  18. 用GDB调试Segmentation 段错误【转】
  19. C++标准模板库(STL)和容器
  20. 快速排序——PowerShell版

热门文章

  1. Partitioned Replacement for Cache Memory
  2. 创建Django项目(七)——表单
  3. hihocoder1496(高维前缀和)
  4. Network problem solving flow chart
  5. Windows 老是弹出要自动拨号连接怎么办
  6. JavaSE入门学习5:Java基础语法之keyword,标识符,凝视,常量和变量
  7. react 项目实战(六)提取布局组件
  8. hdu 1565 方格取数(1)(状态压缩dp)
  9. Trie树(Prefix Tree)介绍
  10. datatables对于某一特定的列进行自定义排序