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)的更多相关文章

  1. 相似性度量(Similarity Measurement)与“距离”(Distance)

    在做分类时常常需要估算不同样本之间的相似性度量(Similarity Measurement),这时通常采用的方法就是计算样本间的“距离”(Distance).采用什么样的方法计算距离是很讲究,甚至关 ...

  2. 海明距离hamming distance

    仔细阅读ORB的代码,发现有很多细节不是很明白,其中就有用暴力方式测试Keypoints的距离,用的是HammingLUT,上网查了才知道,hamming距离是相差位数.这样就好理解了. 我理解的Ha ...

  3. Scipy教程 - 距离计算库scipy.spatial.distance

    http://blog.csdn.net/pipisorry/article/details/48814183 在scipy.spatial中最重要的模块应该就是距离计算模块distance了. fr ...

  4. [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 & ...

  5. Q - Euclid in Manhattan(欧几里德距离==曼哈顿距离?)

    Desciption Consider a set of n points in a 2-D plane with integer coordinates. There are various way ...

  6. 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 ...

  7. 相似系数_杰卡德距离(Jaccard Distance)

    python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)https://study.163.com/course/introduction.htm?courseId=1005269003&ut ...

  8. 【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 ...

  9. 数学中的距离distance(未完成)

    manhattan distance(曼哈顿距离) euclidean distance(欧几里得距离) cosine distance(cosine距离) 闵式距离 切比雪夫距离

随机推荐

  1. erlang,elixir安装

    erlang下载地址:https://packages.erlang-solutions.com/erlang/ elixir(precompile版)下载地址:https://github.com/ ...

  2. linux中的chage命令

    在LINUX系统上,密码时效是通过chage命令来管理的. 参数说明:-m 过多少天后可修改密码.为0时代表任何时候都可以更改密码.-M 过多少天后密码过期.-W 用户密码到期前,提前收到警告信息的天 ...

  3. A*寻路算法(JavaScript实现)

    参考资料:http://www.cnblogs.com/zhoug2020/p/3468167.html               http://www.cnblogs.com/lipan/arch ...

  4. 读取xml文件报错:Invalid byte 2 of 2-byte UTF-8 sequence。

    程序读取xml文件后,系统报“Invalid byte 2 of 2-byte UTF-8 sequence”错误,如何解决呢? 1.程序解析xml的时候,出现Invalid byte 2 of 2- ...

  5. git资料图

  6. jQueryDOM操作笔记

    attr(name[,value]):value(任意|函数) $('*').attr('title',function(index,previousValue){ return previousVa ...

  7. Python 3.5 连接Mysql数据库(pymysql 方式)

    由于 MySQLdb 模块还不支持 Python3.x,官方的Mysql连接包只支持到3.4,所以 Python3.5 如果想连接MySQL需要安装 pymysql 模块. pymysql 模块可以通 ...

  8. 使用 KGDB 调试 Kernel On Red Hat Linux

    1. KGDB 简介         KGDB  提供了一种使用 GDB 调试 Linux 内核的机制.使用 KGDB 可以象调试普通的应用程序那样,在内核中进行设置断点.检查变量值.单步跟踪程序运行 ...

  9. 文件消息的简单样式demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. k-sum问题

    给定一个数组,里面的是任意整数,可能有重复,再给定一个目标T,从数组中找出所有和为T的K个数,要求结果中没有重复. Note: Elements in a quadruplet (a,b,c,d) m ...