Holiday teams cattle off season 1 B

B. poo Portal (a)

Topic links: https://ac.nowcoder.com/acm/contest/918/B

topic

Farmer John's farm was the most annoying transport of cow dung. To streamline the process, he created a great invention: poo Portal! With the use of a tractor towing carts filled with cow dung compared from one location to another location, he can use the portal to poo dung from one location to another location instantly.

Farmer John's farm was built along a long straight road, so each point on the farm he could simply be represented (the equivalent of a point on the number line) with the location of the place on the road. A portal can use two numbers x and y, x Drag manure is transferred to the place instantaneously y location, and vice versa.

Farmer John wants to place a cow from the transport to the location b, he built a might be helpful to the process portal (Of course, if there is no help, he can not). Please help him find his tractor requires a minimum total distance transport of cow dung.

Input
Input contains only one line, is an integer of four separated by spaces: a and B, indicate the start and end point locations, followed by x and y, it represents the portal. All positions are an integer ranging from 0 ... 100, are not necessarily different.

Export

Output an integer, the minimum distance required for the Farmer John tractors transport of cow dung.

Sample

intput

3 10 8 2

output

3

Thinking

Take the difference between the starting position and the transfer gate can comparison, simple judgment title

 

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int main()
{
    int a,b,x,y;
    cin>>a>>b>>x>>y;
    int cha=abs(a-b);
    int sum=0;
    if(abs(a-x)>abs(a-y))
    {
        sum+=abs(a-y);
        sum+=abs(b-x);
    }
  else if(abs(a-x)<abs(a-y))
    {
        sum+=abs(a-x);
        sum+=abs(b-y);
    } 
    cout<<min(cha,sum)<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Vampire6/p/10992412.html
Recommended