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. EXISTS语句

    通常在我写EXISTS语句时,我会写成IF EXISTS(SELECT TOP(1) 1 FROM XXX),也没细细考究过为什么要这么写,只是隐约认为这样写没有啥问题,那今天就深究下吧! 首先准备测 ...

  2. Git查看、删除、重命名远程分支和tag(转)

    转:http://zengrong.net/post/1746.htm 这篇文章记录我在使用git的过程中碰到远程分支和tag的相关内容,提纲: 查看远程分支 删除远程分支和tag 删除不存在对应远程 ...

  3. Python之字符串小代码解析

    本篇只是拿一段代码来对python中的字符串的一些使用做解释,来让大家更加了解python Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:25: ...

  4. 对Hadoop体系的一点认识

    前言:Hadoop体系核心大多源自Google的思想,里面的思想的确很精彩!比如分布式计算,云的思想等,比起其他简单技术,更使得我想写这文章, 虽然这个东东在一般公司不可能用到! 首先由于hadoop ...

  5. HashMap学习

    HashMap<String, Object> java.util.HashMap<String, Object>   在数组中我们是通过数组下标来对其内容索引的,而在Map中 ...

  6. spring 多线程 注入 服务层 问题

    在用多线程的时候,里面要用到Spring注入服务层,或者是逻辑层的时候,一般是注入不进去的.具体原因应该是线程启动时没有用到Spring实例不池.所以注入的变量值都为null. 详细:http://h ...

  7. PHP单引号和双引号对待变量的不同

    如果一个变量放在单引号中,会被当作字符串来处理,如果是放在双引号中,则会被当值一个变量来处理(此时可以用 {}扩起来,也可以不用). <?php $txt = "hello, this ...

  8. 在本地创建angular-ui/bootstrap项目

    在本地创建完整的angular-ui/Bootstrap项目 git clone the repo, then switch to the tag you want,then use grunt bu ...

  9. phpstudy 出现“请自行检查是否安装VC9运行库??”问题 -- 缺少vc9库

    phpStudy是一款PHP调试环境的程序集成包,该程序包集成最新的Apache+PHP+MySQL+phpMyAdmin+ZendOptimizer,一次性安装,无须配置即可使用,是非常方便.好用的 ...

  10. eclipse中安装adt插件

    对于程序开发的学者来说,eclipse并不陌生,它为我们提供了一个非常广阔的平台来开发程序.同样我们也可以用它来开发android程序.但是在eclipse中并不能直接开发android程序,需要我们 ...