D-Professor GukiZ's Robot

D - Professor GukiZ’s Robot
Time Limit:500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit

Status

Practice

CodeForces 620A
Description
Professor GukiZ makes a new robot. The robot are in the point with coordinates (x1, y1) and should go to the point (x2, y2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position.

Input
The first line contains two integers x1, y1 ( - 109 ≤ x1, y1 ≤ 109) — the start position of the robot.

The second line contains two integers x2, y2 ( - 109 ≤ x2, y2 ≤ 109) — the finish position of the robot.

Output
Print the only integer d — the minimal number of steps to get the finish position.

Sample Input
Input
0 0
4 5
Output
5
Input
3 4
6 1
Output
3
Hint
In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its y coordinate and get the finish position.

In the second example robot should simultaneously increase x coordinate and decrease y coordinate by one three times.

题意:给出两组坐标,从一点移动到另一点,一次只能从一个整数坐标移动到下一个整数坐标。也就是说,把坐标轴看成网状的话,上下左右移动和对角线移动都是等效的。

思路,两组坐标相加,得到的新坐标看作是矩形,题意也就是从矩形一端移动到对角线一端

或许此题难点就在理解题意吧

代码

#include<cstdio>
#include<stack>
#include<cstring>
#include<cctype>
#include<cstdlib>
using namespace std;
int main()
{
    long long int x1,x2,y1,y2;
    scanf("%lld %lld",&x1,&y1);
    scanf("%lld %lld",&x2,&y2);
    long long int x,y;//记录矩形边长
    x=x1>x2?x1-x2:x2-x1;
    y=y1>y2?y1-y2:y2-y1;
    printf("%lld\n",max(x,y));
}

你可能感兴趣的:(水)