P26674 [AtCoder] Takahashi and Manhattan
入门
题目描述

Problem Description

Takahashi is in Manhattan. Manhattan is divided by north-south roads and east-west roads, and all roads are very long, so any pair of north-south roads and east-west roads intersect, creating intersections at these points. North-south roads do not intersect with each other, and east-west roads do not intersect with each other either.

Let's denote the intersection of the x-th north-south road from the west and the y-th east-west road from the south as $ (x,y) $.

Takahashi is thinking of moving from intersection $ (x_1,y_1) $ to intersection $ (x_2,y_2) $. What is the minimum number of intersections he must pass through? The intersections passed through include the starting intersection $ (x_1,y_1) $ and the destination intersection $ (x_2,y_2) $.

Write a program to find the number of intersections Takahashi must pass through.

Input Format

The input is given from the standard input in the following format:

$ x_1 $ $ y_1 $ $ x_2 $ $ y_2 $

  • The first line contains the coordinates of the intersection where Takahashi initially is, $x_1,\ y_1\ (1\ ≦\ x_1,\ y_1\ ≦\ 100,000)$.
  • The second line contains the coordinates of the destination intersection, $x_2,\ y_2\ (1\ ≦\ x_2,\ y_2\ ≦\ 100,000)$.
  • It is guaranteed that $(x_1,\ y_1)\ ≠\ (x_2,\ y_2)$, meaning the destination intersection is different from the starting intersection.

Output Format

Output one line containing the minimum number of intersections Takahashi must pass through to go from the starting intersection to the destination intersection.

Do not forget the newline at the end of the line.

Sample Input and Output

Sample Input #1

3 3
2 5

Sample Output #1

4

Sample Input #2

1 2
1 1

Sample Output #2

2

Sample Input #3

20 40
32 64

Sample Output #3

37

Notes/Hints

Sample Explanation 1

 S is the starting intersection, and T is the destination intersection. For example, moving from $ (3,3) $ -> $ (2,3) $ -> $ (2,4) $ -> $ (2,5) $ allows you to reach the destination by passing through 4 intersections. It is not possible to pass through fewer than 4 intersections.

Sample Explanation 2

The optimal path is from $ (1,2) $ -> $ (1,1) $.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 2 5
样例输出
4