CF883M.Quadcopter Competition

普及-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:

  • start the race from some point of a field,
  • go around the flag,
  • close cycle returning back to the starting point.

Polycarp knows the coordinates of the starting point (_x_1, _y_1) and the coordinates of the point where the flag is situated (_x_2, _y_2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (x, y) to any of four points: (x - 1, y), (x + 1, y), (x, y - 1) or (x, y + 1).

Thus the quadcopter path is a closed cycle starting and finishing in (_x_1, _y_1) and containing the point (_x_2, _y_2) strictly inside.

The picture corresponds to the first example: the starting (and finishing) point is in (1, 5) and the flag is in (5, 2).

What is the minimal length of the quadcopter path?

Polycarp 参加一场四旋翼飞行器比赛。根据规则,飞行机器人需满足以下要求:

  • 从场地上的某一点出发开始比赛;
  • 绕过旗帜;
  • 形成闭合回路并返回起点。

Polycarp 已知起点坐标为 (x1, y1)(x_1,\,y_1),旗帜所在点坐标为 (x2, y2)(x_2,\,y_2)。Polycarp 的四旋翼飞行器每步只能沿场地边方向飞行,即每步恰好使横坐标或纵坐标变化 11。换言之,飞行器在一步内可从点 (x, y)(x,\,y) 飞至以下四个点之一:(x−1, y)(x-1,\,y)、(x+1, y)(x+1,\,y)、(x, y−1)(x,\,y-1) 或 (x, y+1)(x,\,y+1)。

因此,四旋翼飞行器的路径是一条闭合回路,起点与终点均为 (x1, y1)(x_1,\,y_1),且点 (x2, y2)(x_2,\,y_2) 严格位于该回路内部。


上图对应第一个样例:起点(同时也是终点)为 (1, 5)(1,\,5),旗帜位于 (5, 2)(5,\,2)。

求四旋翼飞行器路径的最小长度。

输入格式

The first line contains two integer numbers _x_1 and _y_1 ( - 100 ≤ _x_1, _y_1 ≤ 100) — coordinates of the quadcopter starting (and finishing) point.

The second line contains two integer numbers _x_2 and _y_2 ( - 100 ≤ _x_2, _y_2 ≤ 100) — coordinates of the flag.

It is guaranteed that the quadcopter starting point and the flag do not coincide.

第一行包含两个整数 x1x_1 和 y1y_1(−100≤x1,y1≤100-100 \le x_1, y_1 \le 100),表示四旋翼飞行器的起点(同时也是终点)的坐标。

第二行包含两个整数 x2x_2 和 y2y_2(−100≤x2,y2≤100-100 \le x_2, y_2 \le 100),表示旗帜的坐标。

保证四旋翼飞行器的起点与旗帜的位置不重合。

输出格式

Print the length of minimal path of the quadcopter to surround the flag and return back.

输出四旋翼无人机环绕旗帜并返回起点的最短路径长度。

输入输出样例

  • 输入#1

    1 5
    5 2

    输出#1

    18
  • 输入#2

    0 1
    0 0

    输出#2

    8

输入解题思路,AI测评打分。不知道怎么写?

首页