Flee
SRM 662 · 2015-06-30 · by cgy4ever
Problem Statement
You are given
Formally, for any point P in the plane, we define its safety level S(P) as the distance to the closest guard. The safety level of a path is the minimum safety level of a point on the path. Find a path with the largest possible safety level and return its safety level.
Notes
- Your return value must have an absolute or a relative error smaller than 1e-9.
Constraints
- x will contain between 1 and 3 elements, inclusive.
- x and y will contain the same number of elements.
- Each element in x and y will be between -1,000 and 1,000, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
{1,1,-7}
{5,-5,0}
Returns: 5.0
You can go from (0, 0) to (10^100, 0) directly. The safety level of this path is 5, because when you are at (1, 0) the distance to the closest guard is 5.
{1,1}
{-5,-5}
Returns: 5.0990195135927845
One optimal path is the following polyline: (0, 0) -- (-100, 0) -- (-100, -10000) -- (10^100, 0).
{1,1,-8}
{5,-5,0}
Returns: 5.0990195135927845
{232,312,-432}
{498,-374,24}
Returns: 432.6661530556787
{0}
{0}
Returns: 0.0
Each valid path starts in the point (0, 0). This point contains a guard and therefore its safety level is 0. Hence, the safety level of any valid path will be 0.
Submissions are judged against all 77 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Flee with a public method double maximalSafetyLevel(vector<int> x, vector<int> y) · 77 test cases · 2 s / 256 MB per case