题目描述:
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.
输入描述:
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.
输出描述:
Print the only integer d — the minimal number of steps to get the finish position.
输入:
0 0
4 5
3 4
6 1
输出:
5
3
题意:
一开始在(x1,y1)最后在(x2,y2)每秒钟内横坐标最多变化1(也可以不变化)纵坐标也是问最少几秒钟到
题解:
找到横坐标的最大值和纵坐标的最大值
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int abs(int x){
if(x < 0) x = -1 * x;
return x;
}
int main(){
int x1,y1,x2,y2;
while(scanf("%d%d%d%d",&x1,&y1,&x2,&y2)!=EOF){
int x = abs(x1 - x2);
int y = abs(y1 - y2);
int maxx = max(x,y);
printf("%d\n",maxx);
}
return 0;
}