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距离) 闵式距离 切比雪夫距离
随机推荐
- SpringMVC集成缓存框架Ehcache
在互联网应用中,应用并发比传统企业及应用会高出很多.解决并发的根本在于系统的响应时间与单位时间的吞吐量.思路可分为:一减少系统的不必要开支(如缓存),二是提高系统单位时间内的运算效率(如集群). 在硬 ...
- poj 2761 Feed the dogs (treap树)
/************************************************************* 题目: Feed the dogs(poj 2761) 链接: http: ...
- sql一对多的两个表的update
scie_apprecord仪器表 和 scie_apporder仪器预约时间表 ,一个仪器可以有多条预约时间. 仪器表: 预约时间表: 需求: 由于一个仪器有好多条预约记录,将预约时间表的最 ...
- Form表单(回车)提交问题
我们有时候希望回车键敲在文本框(input element)里来提交表单(form),但有时候又不希望如此.比如搜索行为,希望输入完关键词之后直接按回车键立即提交表单,而有些复杂表单,可能要避免回车键 ...
- 类的static成员并用其实现一个单例模式
对于特定类型的全体对象而言,有时候可能需要访问一个全局的变量.比如说统计某种类型对象已创建的数量.如果我们用全局变量会破坏数据的封装,一般的用户代码都可以修改这个全局变量,这时我们可以用类的静态成员来 ...
- string&&char 小技巧
关于string =,assign() //赋以新值 swap() //交换两个字符串的内容 +=,append(),push_back() //在尾部添加字符 insert() //插入字符 ...
- oracle 密码过期处理
1.查看用户的proifle是哪个,一般是default sql>SELECT username,PROFILE FROM dba_users; 2.查看指定概要文件(如default)的密码有 ...
- ActionBarSherlock环境搭建
1.在官网http://actionbarsherlock.com/下载ActionBarSherlock包解压到. 2.创建自己的Android工程: 3.File -> New -> ...
- city-picker 选择省市县的一个控件,好用。
我觉得好奇怪,这么好一个插件,为什么没有设置值的方法,还是我才疏学浅?? 我看有的人做法是把,把源代码里面的自动扫描机制注释掉 // $(function () { // $('[data-toggl ...
- 说说C#的async和await 解决卡顿问题 转
C# 5.0中引入了async 和 await.这两个关键字可以让你更方便的写出异步代码. 看个例子: 可以看到,async和await关键字只是把上面的代码变得更简单易懂而已. public cla ...