当前位置:网站首页>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 (3): multidimensional Kalman filter
- Mangodb simple to use
- "Weilai Cup" 2022 Niuke summer multi school training camp 1
- 巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...
- 一些实用、常用、效率越来越高的 Kubernetes 别名
- Principle of flex:1
- qt中使用sqlite同时打开多个数据库文件
- Can "Gulangyu yuancosmos" become an "upgraded sample" of China's cultural tourism industry
- PVT's spatial reduction attention (SRA)
- 对 int 变量赋值的操作是原子的吗?
猜你喜欢

CUDA programming-02: first knowledge of CUDA Programming

ctfshow 终极考核

Can "Gulangyu yuancosmos" become an "upgraded sample" of China's cultural tourism industry

Music experience ceiling! Emotional design details of 14 Netease cloud music
![[micro service ~sentinel] sentinel dashboard control panel](/img/df/2fbe7826ea2b80a81d29351052ae28.png)
[micro service ~sentinel] sentinel dashboard control panel

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

PyTorch自定义CUDA算子教程与运行时间分析

Network IO summary

Is the operation of assigning values to int variables atomic?

“蔚来杯“2022牛客暑期多校训练营1
随机推荐
Matlab数据导入--importdata和load函数
【云原生之kubernetes实战】在kubernetes集群下部署Rainbond平台
全排列递归思路整理
如何在B站上快乐的学习?
BEVFormer: Learning Bird’s-Eye-View Representation from Multi-Camera Images via Spatiotemporal Trans
500 error reporting
Babbitt | yuan universe daily must read: Guangzhou Nansha released the "Yuan universe nine" measures, and the platform can obtain up to 200million yuan of financial support
Flex layout (actual Xiaomi official website)
[interprocess communication IPC] - semaphore learning
Apple cut its price by 600 yuan, which was almost a devastating blow to the collapse of its domestic flagship mobile phone
Qdoublevalidator does not take effect solution
B tree
5g failed to stimulate the development of the industry, which disappointed not only operators, but also mobile phone enterprises
Unity3d 2021 software installation package download and installation tutorial
How to study happily on station B?
tensorflow包tf.keras模块构建和训练深度学习模型
PyTorch自定义CUDA算子教程与运行时间分析
flex:1的原理
Ztree custom title attribute
SQL exercise set
