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距离) 闵式距离 切比雪夫距离
随机推荐
- php常用的数组函数
array_change_key_case -- 返回字符串键名全为小写或大写的数组 array_chunk -- 将一个数组分割成多个 array_combine -- 创建一个数组,用一个数组的 ...
- submit 后台运行代码
if EX_TABLE-matnr is not initial and EX_TABLE-KUNDE is not initial. wa_rspar-selname = 'MATNR' ...
- 记录那些我不清楚的知识点(HTML)
<div class="link"><a href="http://www.baidu.com/" target="iframeHt ...
- jQuery Mobile 列表内容
jQuery Mobile 列表缩略图 对于大于 16x16px 的图像,请在链接中添加 <img> 元素. jQuery Mobile 将自动把图像调整至 80x80px: 实例: &l ...
- linux shell执行中需要交互输入回车,Yes/NO Y/N
最近写自动安装脚本遇到redis-server安装的时候,需要输入3个回车,对此尝试无果,最后google比较满意的解决办法: shell 脚本需要交互,比如输入回车,输入YES/NO Y/N之类进行 ...
- const变量初始化问题
在C++中const变量定义时必须进行初始化,否则无法通过编译. 初始化的方式有多种,可以通过字面值对其进行初始化,也可以通过变量对其初始化,或其他方式,只要能给const变量赋初值即可(当然初值应该 ...
- c++ 覆盖、重载与隐藏
成员函数被重载的特征:(1)相同的范围(在同一个类中):(2)函数名字相同:(3)参数不同:(4)virtual 关键字可有可无.覆盖是指派生类函数覆盖基类函数,特征是:(1)不同的范围(分别位于派生 ...
- 下拉tableView实现类似微信中带图的灰色背景
UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(, -, ScreenWidth, )]; UIImageView *iconIma ...
- 一个未解决的samba问题
话说,现在的打复印扫描一体机的扫描功能十分丰富,扫描后的文件可以通过邮件发送,可以发到windows的共享.一直用着windows共享的方式,但是windows系统占用的内存还是略大,想把这个共享放到 ...
- 用Action的属性接受参数
版本, @Override是Java5的元数据,自动加上去的一个标志,告诉你说下面这个方法是从父类/接口 继承过来的,需要你重写一次,这样就可以方便你阅读,也不怕会忘记@Override是伪代码,表示 ...