如果点 1 在 的位置,点 2 在 的位置上,那么:
曼哈顿距离实际上就是 ( 表示求 的绝对值)。
代码
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d; // a, b, c, d 分别表示题面的 x1, y1, x2, y2,如果使用 y1 作为变量名会与 bits/stdc++.h 的变量重名,于是就 CE 了:https://algobeat.online/submission/8681
int main(){
cin>>a>>b>>c>>d;
cout<<abs(a-c)+abs(b-d); // abs 函数表示求绝对值
return 0;
}
暂无评论