AcWing 1219. 移动距离
原题链接
简单
作者:
牛奶小柒Luke
,
2021-03-27 13:57:42
,
所有人可见
,
阅读 210
曼哈顿距离:|x1 - x2| + |y1 - y2|
欧几里德距离: fabs((x1 - x2) + (y1- y2))
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e4 + 10;
int m,n,w;
int main(){
scanf("%d%d%d",&w,&m,&n);
m--,n--;
int x1 = m / w,x2 = n / w;
int y1 = m % w,y2 = n % w;
if(!(x1 & 1)) y1 = w - 1 - y1;
if(!(x2 & 1)) y2 = w - 1 - y2;
printf("%d\n",abs(x1 - x2) + abs(y1 - y2));
return 0;
}