You have a house, which you model as an axis-aligned rectangle with corners at (x1; y1) and (x2; y2).
You also have a goat, which you want to tie to a fence post located at (x; y), with a rope of length
l. The goat can reach anywhere within a distance l from the fence post.
Find the largest value of l so that the goat cannot reach your house.
Input
Input consists of a single line with six space-separated integers x, y, x1, y1, x2, and y2. All the
values are guaranteed to be between 􀀀1000 and 1000 (inclusive).
It is guaranteed that x1 < y1 and x2 < y2, and that (x; y) lies strictly outside the axis-aligned
rectangle with corners at (x1; y1) and (x2; y2).
Output
Print, on one line, the maximum value of l, rounded and displayed to exactly three decimal places.
Sample Input and Output
7 4 0 0 5 4

2.000

Sample Input and Output
6 0 0 2 7 6

2.000

Sample Input and Output
4 8 7 8 9 9

3.000
 

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
using namespace std;
int x,y,hx1,hy1,hx2,hy2;
double S(int a,int b,int c,int d){
    return sqrt((a-c)*(a-c)+(b-d)*(b-d));

}
int main()
{
    scanf("%d%d%d%d%d%d",&x,&y,&hx1,&hy1,&hx2,&hy2);
    double ans=0,tmp1,tmp2;
    if(hx1<=x&&x<=hx2){
        ans=min(abs(hy1-y),abs(hy2-y));
    }else if(hy1<=y&&y<=hy2){
        ans=min(abs(hx1-x),abs(hx2-x));
    }else{
        tmp1=min(S(x,y,hx1,hy1),S(x,y,hx2,hy2));
        tmp2=min(S(x,y,hx1,hy2),S(x,y,hx2,hy1));
        ans=min(tmp1,tmp2);
    }
    printf("%.3lf\n",ans+0.00000001);
    //cout << "Hello world!" << endl;
    return 0;
}