Goat Rope
InterviewTime limit2sMemory limit512 MB
Given a point outside an axis-aligned rectangle, print the minimum distance from the point to the rectangle's boundary.
- Level
Medium4 of 10
- Topics
- Geometry, Math, Implementation
- Solved
- No attempts yet
Problem
You have a fence post at the point in the plane, and a goat is tethered to it by a rope. You also have a house, which you model as an axis-aligned rectangle with diagonally opposite corners at the points and . You want to choose a rope length that guarantees the goat cannot reach the house. Find the minimum distance from the post to the house, so that you can be sure to use a shorter rope.
Input
The input consists of a single line containing six space-separated integers , , , , , and , each in the range .
It is guaranteed that and , and that lies strictly outside the axis-aligned rectangle with corners at and .
Output
Print the minimum distance from the goat's post to the house, with a relative or absolute error of at most .