走方格
链接:https://ac.nowcoder.com/acm/contest/368/A
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld
题目描述
在一个n*n的方格中,你只能斜着走。
你还有一次上下左右走的机会
给你一个起点(sx,sy),和终点(ex,ey),询问从起点到终点最少走多少步。
输入描述:
一行5个整数,n,sx,sy,ex,ey。
1≤sx,sy,ex,ey≤n≤1e18
输出描述:
一行一个整数,表示从起点到终点最少走多少步。
示例1
输入
8 2 3 7 5
输出
5
取x与y的最大步数即可
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
long long int n, sx, sy, ex, ey;
scanf("%lld %lld %lld %lld %lld", &n, &sx, &sy, &ex, &ey);
long long int ans = max(abs(sx-ex), abs(sy-ey));
printf("%lld\n", ans);
}