codeforces620A

Professor GukiZ's Robot

 CodeForces - 620A 

机器人很好玩

一开始在(x1,y1)

最后在(x2,y2)

每秒钟内横坐标最多变化1(也可以不变化)纵坐标也是

问最少几秒钟到

Inputx1 和 x2 绝对值在10^9以内Output最少几秒可以走到Examples

Input
0 0
4 5
Output
5
Input
3 4
6 1
Output
3

sol:易知答案为max(abs(x1-x2),abs(y1-y2))
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0;
    bool f=0;
    char ch=' ';
    while(!isdigit(ch))
    {
        f|=(ch=='-'); ch=getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
    }
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0)
    {
        putchar('-'); x=-x;
    }
    if(x<10)
    {
        putchar(x+'0');    return;
    }
    write(x/10);
    putchar((x%10)+'0');
    return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('
')
int main()
{
    int x1,y1,x2,y2;
    R(x1); R(y1); R(x2); R(y2);
    Wl(max(abs(x1-x2),abs(y1-y2)));
    return 0;
}
View Code
 
原文地址:https://www.cnblogs.com/gaojunonly1/p/10580556.html