Q - Euclid in Manhattan(欧几里德距离==曼哈顿距离?)
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(欧几里德距离==曼哈顿距离?)的更多相关文章
- Hdu 4312-Meeting point-2 切比雪夫距离,曼哈顿距离,前缀和
题目: http://acm.hdu.edu.cn/showproblem.php?pid=4312 Meeting point-2 Time Limit: 2000/1000 MS (Java/Ot ...
- BZOJ3170 [Tjoi2013]松鼠聚会 切比雪夫距离 - 曼哈顿距离 - 前缀和
BZOJ3170 题意: 有N个小松鼠,它们的家用一个点x,y表示,两个点的距离定义为:点(x,y)和它周围的8个点即上下左右四个点和对角的四个点,距离为1.现在N个松鼠要走到一个松鼠家去,求走过的最 ...
- K-means真的不能使用曼哈顿距离吗?
问题 说到k-means聚类算法,想必大家已经对它很熟悉了,它是基于距离计算的经典无监督算法,但是有一次在我接受面试时,面试官问了我一个问题:“k-means为什么不能使用曼哈顿距离计算,而使用欧式距 ...
- Atitti knn实现的具体四个距离算法 欧氏距离、余弦距离、汉明距离、曼哈顿距离
Atitti knn实现的具体四个距离算法 欧氏距离.余弦距离.汉明距离.曼哈顿距离 1. Knn算法实质就是相似度的关系1 1.1. 文本相似度计算在信息检索.数据挖掘.机器翻译.文档复制检测等领 ...
- hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4666 Hyperspace (最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 暴力三维树状数组求曼哈顿距离求最值——牛客多校第八场D
涉及的知识点挺多,但是大多是套路 1.求曼哈顿距离的最值一般对所有情况进行讨论 2.三维树状数组用来求前缀最大值 /* 有一个三维坐标系(x,y,z),取值范围为[1,n],[1,m],[1,h],有 ...
- hdu4666 Hyperspace ——曼哈顿距离
link:http://acm.hdu.edu.cn/showproblem.php?pid=4666 这题学会了怎么处理曼哈顿距离. 比如维数是k,那么每个点有2^k个状态,求出在每个状态下,所有点 ...
随机推荐
- android开发里跳过的坑——图片文件上传失败
使用的apache的httpclient的jar包,做的http图片上传,上传时,服务器总返文件格式不对.后来发现,是由于在创建FileBody时,使用了默认的ContentType引起的.所以服务器 ...
- Ftp启动与关闭
//启动 service vsftpd start //关闭 service vsftpd stop 查看进程 ps -ef | grep ftp root : ? :: /usr/sbin/vsft ...
- Linux下汇编语言学习笔记26 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- AjaxFileUpload文件上传组件(php+jQuery+ajax)
jQuery插件AjaxFileUpload可以实现ajax文件上传,下载地址:http://www.phpletter.com/contents/ajaxfileupload/ajaxfileupl ...
- Codeforces 651D Image Preview【二分+枚举】
题意: 若干张照片,从头开始可以向左右两边读,已经读过的不需要再读,有的照片需要翻转,给定读.滑动和翻转消耗的时间,求在给定时间内最多能读多少页? 分析: 首先明确,只横跨一次,即先一直读一边然后再一 ...
- HDU——2063 过山车
过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- dtrace-conf 2016
https://www.joyent.com/about/events/2016/dtrace-conf
- easyui datagrid-detailview 嵌套高度自适应
实现效果 原因 异步加载,明细展开时,可能会遇到父列表不能自动适应子列表高度的变化 具体代码 $('#centerdatagrid').datagrid({ url:'${ctx}/offer/off ...
- 华为AR1220
今天刚刚收到华为AR1220,以为直接就可以用web界面管理,结果开机后才知道web管理界面需要激活.下面简单分享这个过程:*** 用控制台线(一边RJ45,一边9针串)连接Router consol ...
- UML基础与应用总结
敲响一段键盘的乐响曲,一段路程留下一些足迹. UML.是Unified-Modeling-Language的缩写. 首先要明白知道它是一种可视化的建模语言. 什么是UML基 ...