这是一道有关于直角坐标系的题目,手动算一下就可以找到规律。

不难道想到分类讨论,我们分三类(飞行器与旗子应该不会重叠):

  1. $x_1 ≠ x_2$ 且 $y_1 ≠ y_2$。也就是样例给的图片,我们观察一下,发现比普通的求两点间的两倍曼哈顿距离又多了 $4$。所以此时的答案为 ${|x_1 - x_2| + |y_1 - y_2|} \times 2 + 4$。

  2. $x_1 ≠ x_2$ 且 $y_1 = y_2$。同样的,进行手推,发现这次是两倍曼哈顿距离又多了 $6$。所以此时的答案为 ${|x_1 - x_2|} \times 2 + 6$。

  3. $x_1 = x_2$ 且 $y_1 ≠ y_2$。与 $2$ 的情况的本质相同,也是两倍曼哈顿距离又多了 $6$。所以此时的答案为 ${|y_1 - y_2|} \times 2 + 6$。

1

综上所述,我们可以得到代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
inline int read ();
int a,b,c,d;
int main ()
{
a = read ();b = read ();c = read ();d = read ();
if (a != c && b != d) printf ("%d\n",2 * (abs (a - c) + abs (b - d)) + 4);
if (a == c) printf ("%d\n",2 * abs (b - d) + 6);
if (b == d) printf ("%d\n",2 * abs (a - c) + 6);
return 0;
}
inline int read ()
{
int s = 0;int f = 1;
char ch = getchar ();
while ((ch < '0' || ch > '9') && ch != EOF)
{
if (ch == '-') f = -1;
ch = getchar ();
}
while (ch >= '0' && ch <= '9')
{
s = s * 10 + ch - '0';
ch = getchar ();
}
return s * f;
}