Swimming with Sharks
Time limit1sMemory limit128 MB
On a w by h grid starting and ending at (1,1), plan t moves (or stays) to maximize the minimum Euclidean distance to any shark present at each time step.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Binary search, BFS, Math
- Solved
- No attempts yet
Problem
At one of the beaches in La Jolla, right by the pier, there are quite a few leopard sharks (they are only about 4 feet long, much smaller than most sharks). Some people find it thrilling to swim in the water together with these sharks. The contest organizers unanimously agree that this is not the greatest idea, and that if they ever found themselves in the water with a bunch of leopard sharks, their main goal would be to stay as far away from them as possible. Luckily, a (waterproof) computer can help with exactly that.
We model the water as a two-dimensional grid of integer coordinates. At time you start at point . In each time step you may swim one square right, left, up, or down, or stay where you are, as long as you never leave the grid. You are given the positions of the sharks at various times, together with a time horizon . You must plan your moves so as to stay as far from every shark as possible over the time steps.
More precisely, at each time step consider the distance from your position to the nearest shark that is present at that time step; let be the smallest such distance over all time steps (the closest you ever come to a shark). The distance between two points and is the Euclidean distance . Your goal is to choose a move plan that makes as large as possible while ending up back at position at time .
Input
The first line contains a number , the number of data sets in the input. It is followed by data sets of the following form.
The first line of each data set contains four integers , , , . Here are the width and height of the water area, is the number of time steps you spend in the water, and is the number of shark sightings.
This is followed by lines, each containing three integers , , with , , and . Such a line means that at time there is a shark at position . The sightings are not sorted by any particular parameter.
Output
For each data set, first output "Data Set x:" on a line by itself, where is the number of the data set (starting from ). Then output the closest you ever come to a shark in the best possible move plan, rounded to two decimals. (An output of means you cannot avoid occupying the same square as a shark at some time.)