当前位置:网站首页>Save Xiaoyi from Netease written test -- a typical application of Manhattan distance
Save Xiaoyi from Netease written test -- a typical application of Manhattan distance
2022-07-27 09:09:00 【Hua Weiyun】
Preface
First, let's introduce Manhattan , Manhattan is a very prosperous neighborhood , skyscrapers , The streets crisscross , from A The location arrives at B The location has no straight path , We have to make a detour , And at least through C place , go AC and CB To get to , Because the streets are very regular ,ACB Like a right angle 3 Horn shape ,AB It's a hypotenuse ,AC and CB It's a right angle side , According to Pythagoras ( Pythagorean ) Theorem , Or vector theory , Can know to use AC and CB Can express AB The length of .
In early computer graphics , The screen is made up of pixels , Is an integer , The coordinates of points are also generally integers , The reason is that floating point operations are expensive , It's very slow and it's a little bit of an error , If used directly AB Distance of , You have to do floating-point operations , If you use AC and CB, Then just calculate the addition and subtraction method , This greatly improves the speed of computation , And no matter how many times it's accumulated , There will be no error . therefore , Computer graphics borrows Manhattan to name this representation .
Manhattan distance : The distance between the two points in the north-south direction plus the distance in the east-west direction , namely d(i,j)=|xi-xj|+|yi-yj|. For one with a due south due north 、 It is a regular Town Street in the direction of East and West , The distance from one point to another is the distance traveled in the north-south direction plus the distance traveled in the east-west direction .
By analyzing the following topics , It is known that Manhattan distance can be used to calculate to (1,1) Point the nearest point , The result value can be calculated according to Manhattan distance . If you don't understand the definition and application of Manhattan , Observe by drawing , In fact, you can also get the answer . Obviously, if you had understood the definition and application of Manhattan distance before , The problem is easy to catch !
The code is as follows :
The distance between Manhattan and Euclid : red 、 The blue and yellow lines indicate that all Manhattan distances have the same length (12), The green line indicates that Euclidean distance is 6×√2 ≈ 8.48 The length of .
Euclid ( European style for short ) Range of application :m The real distance between two points in dimensional space . Its calculation formula is as follows :
The formula of two-dimensional space
0ρ = sqrt( (x1-x2)^2+(y1-y2)^2 )
The formula of three-dimensional space
0ρ = √( (x1-x2)^2+(y1-y2)^2+(z1-z2)^2 )
边栏推荐
- Deep understanding of Kalman filter (2): one dimensional Kalman filter
- B tree
- HUAWEI 机试题:字符串变换最小字符串 js
- 2040: [Blue Bridge Cup 2022 preliminary] bamboo cutting (priority queue)
- New year's goals! The code is more standardized!
- [interprocess communication IPC] - semaphore learning
- NiO example
- Matlab uses m file to produce fuzzy controller
- 罗克韦尔AB PLC 通过RSLinx Classic与PLC建立通信的具体方法步骤
- Tensorflow package tf.keras module construction and training deep learning model
猜你喜欢
![[I2C reading mpu6050 of Renesas ra6m4 development board]](/img/1b/c991dd0d798edbb7410a1e16f3a323.png)
[I2C reading mpu6050 of Renesas ra6m4 development board]

"Weilai Cup" 2022 Niuke summer multi school training camp 1

Some practical, commonly used and increasingly efficient kubernetes aliases

拍卖行做VC,第一次出手就投了个Web3

【微服务~Sentinel】Sentinel之dashboard控制面板

Five kinds of 2D attention finishing (non local, criss cross, Se, CBAM, dual attention)

Explanation of common basic controls for C # form application (suitable for Mengxin)

Apple cut its price by 600 yuan, which was almost a devastating blow to the collapse of its domestic flagship mobile phone

Pyqt5 rapid development and practice 4.1 qmainwindow

Aruba learning notes 10 security authentication portal authentication (web page configuration)
随机推荐
接口测试工具-Postman使用详解
CUDA programming-04: CUDA memory model
新年小目标!代码更规范!
Size limit display of pictures
“蔚来杯“2022牛客暑期多校训练营1
基于ArkUI eTS开发的坚果食谱(NutRecipes
Detailed explanation of two methods of Sqlalchemy
[interprocess communication IPC] - semaphore learning
巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...
D3.v3.js data visualization -- pictures and tips of force oriented diagram
QT uses SQLite to open multiple database files at the same time
对 int 变量赋值的操作是原子的吗?
被三星和台积电挤压的Intel终放下身段,为中国芯片定制芯片工艺
TensorFlow损失函数
【ACL2020】一种新颖的成分句法树序列化方法
Interface test tool -postman usage details
Replace restricts the text box to regular expressions of numbers, numbers, letters, etc
Deep understanding of Kalman filter (1): background knowledge
"Weilai Cup" 2022 Niuke summer multi school training camp 1
1.3.1 Full Permutation Problem
