Manhattan distance(for lab)
Input four integer x1, y1, x2, y2, which is mean that the coordinates of two points A(x1, y1), B(x2, y2). [0 <= x1,y1,x2,y2 <= 10000]
Please output manhatton distance between the two points.
output format:there is an "\n" behind the manhatton distance.
For example
[Input]
0 0 1 1
[Output]
2
hint
Manhattan distance, considered by Hermann Minkowski in 19th century Germany, is a form of geometry in which the usual distance function of metric or Euclidean geometry is replaced by a new metric in which the distance between two points is the sum of the absolute differences of their Cartesian coordinates. ——Find in Wiki
d(i,j)=|X1-X2|+|Y1-Y2|.
if you want to use the abs() function to calculate the absolute value, you should include the stdlib.h head file.
You also can compare X1 and X2.And then use the big value to minus the small value.
Input--> use scanf function
Output--> user printf function
tpis:Just output the manhatton distance and "\n". You do not need to output other information, especially Chinese string.
.#include <stdio.h>
.#include <stdlib.h>
.
.int main() {
. int x1, y1, x2, y2;
. int sum = ;
.
. scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
. sum = abs(x1 - x2) + abs(y1 - y2);
. printf("%d\n", sum);
.
. return ;
.}
要注意的就是求绝对值用abs(),需要头文件<stdlib.h>
Manhattan distance(for lab)的更多相关文章
- 相似性度量(Similarity Measurement)与“距离”(Distance)
在做分类时常常需要估算不同样本之间的相似性度量(Similarity Measurement),这时通常采用的方法就是计算样本间的“距离”(Distance).采用什么样的方法计算距离是很讲究,甚至关 ...
- 海明距离hamming distance
仔细阅读ORB的代码,发现有很多细节不是很明白,其中就有用暴力方式测试Keypoints的距离,用的是HammingLUT,上网查了才知道,hamming距离是相差位数.这样就好理解了. 我理解的Ha ...
- Scipy教程 - 距离计算库scipy.spatial.distance
http://blog.csdn.net/pipisorry/article/details/48814183 在scipy.spatial中最重要的模块应该就是距离计算模块distance了. fr ...
- [Swift]LeetCode1030. 距离顺序排列矩阵单元格 | Matrix Cells in Distance Order
We are given a matrix with R rows and C columns has cells with integer coordinates (r, c), where 0 & ...
- Q - Euclid in Manhattan(欧几里德距离==曼哈顿距离?)
Desciption Consider a set of n points in a 2-D plane with integer coordinates. There are various way ...
- Matrix Cells in Distance Order
Matrix Cells in Distance Order We are given a matrix with R rows and C columns has cells with intege ...
- 相似系数_杰卡德距离(Jaccard Distance)
python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)https://study.163.com/course/introduction.htm?courseId=1005269003&ut ...
- 【leetcode】1030. Matrix Cells in Distance Order
题目如下: We are given a matrix with R rows and C columns has cells with integer coordinates (r, c), whe ...
- 数学中的距离distance(未完成)
manhattan distance(曼哈顿距离) euclidean distance(欧几里得距离) cosine distance(cosine距离) 闵式距离 切比雪夫距离
随机推荐
- myeclipse中如何导入mysql-connector-java-5.1.8-bin.jar【环境配置和工具使用】
前提:我建立了一个java project,工程名字为Test,现在需要连接mysql数据库,所以提前从网上将java操作mysql数据库的mysql-connector-java-5.1.8-bin ...
- java_js从字符串中截取数字
var str="1件*20桶*30包*123.45公斤"; var res=str.match(/\d+(\.\d+)?/g); alert(res);
- jquery from提交和post提交
//from 提交 function login(){ $('#login_form').form('submit',{ url: '../../../bagechux ...
- textFiled的placeHolder字体颜色
self.title=@"修改UITextField的placeholder字体颜色"; UITextField *textTF=[[UITextField alloc]initW ...
- Hibernate多对一(注解)
package cqvie.yjq.Util; import java.util.List; import org.hibernate.Query; import org.hibernate.Sess ...
- L440 无线网卡:由于该设备有问题,Windows 已将其停止(代码 43)
最近重装了系统,本来用的好好的,结果重启之后突然无线网卡不能用了,设备管理器老是黄色叹号!无线网卡设备状态:由于该设备有问题,Windows 已将其停止. (代码 43). 无线网卡型号:2 ...
- [z]查表空间使用情况
SELECT UPPER(F.TABLESPACE_NAME) "表空间名",D.TOT_GROOTTE_MB "表空间大小(M)",D.TOT_GROOTTE ...
- io流(详询请加qq:2085920154)
import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class ioTest ...
- 20151207Study
Liberal lawmakers proposed a bill to reduce the cost of medicine for older Americans.自由主义立法者提出一条减少老年 ...
- linux TLS 线程本地变量
最近在写底层hook的时候, 涉及到线程安全问题, 最开始我设计的时候使用的互斥量, 但是考虑到都是底层函数,加锁会导致性能问题, 一直在思考优化方案, 后来偶然想到,java里面有线程本地变量的AP ...