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. ruby Matrix 输出 格式化

    require 'matrix' class Matrix def to_pretty_s s = "" i = 0 while i < self.column_size s ...

  2. 3 Longest Substring Without Repeating Characters

    public int lengthOfLongestSubstring(String s) { long length = s.length(); String tmp = ""; ...

  3. js高级选择器querySelector和querySelectorAll

    querySelector 和 querySelectorAll 方法是 W3C Selectors API规范中定义的.他们的作用是根据 CSS 选择器规范,便捷定位文档中指定元素. 目前几乎主流浏 ...

  4. 04-JAVA中的类和对象

    1. Foo对构造函数进行了重载,那么默认的构造函数就不会被使用,在主类中,定义对象的时候,引用构造函数,却没有参数,自然无法通过编译. 2. 当设定字段初始值在初始化块前面的时候, 很明显使用了前者 ...

  5. TFS 服务端默认端口更改

    由于服务商限制8080,为了外网能访问.如果可以做映射还好.如果不能那就修改默认端口 以下为网上资源 安装完Team Foundation Server 2005 后,默认的端口是8080.如果想要事 ...

  6. linq 实现group by 不使用group关键字 等同lambad表达式中的group join 查询一对多关系

    return from orderInfo in orderEntity.x_s_orderInfo join oState in orderEntity.x_s_oStatuInfo on orde ...

  7. [问题]数据库MySQL和Navicat的乱码问题

    计算机中存储字符需要使用编码集,早期有ASCII集,但是随着技术的发展,ASCII集不能满足需求,出现了越来越多的字符,比如中文字符等.后来又发展出了Unicode.GB2312.utf8等字符集.字 ...

  8. JavaWeb技术(二):DAO设计模式

    1. DAO全称:Data Access Object , 数据访问对象.使用DAO设计模式来封装数据持久化层的所有操作(CRUD),使得数据访问逻辑和业务逻辑分离,实现解耦的目的. 2. 典型的DA ...

  9. android opengl es代码功能

    /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Versi ...

  10. Shell基础-ech0,cat,history,alias,unalias,bash快捷键,wc,执行结果写入文件

    1 系统所支持的shell存放于 /etc/shells 文件中,shell脚本的开头 #!/bing/bash 是指定使用的脚本类型 不能省略,省略之后有些文件可以执行,但容易出错 这行不是注释 2 ...