This page is still under construction.

Parts of this page are still being built. What you see may change.

Swimming with Sharks

Time limit1sMemory limit128 MB

Summary
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 w×hw \times h two-dimensional grid of integer coordinates. At time 11 you start at point (1,1)(1, 1). 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 tt. You must plan your moves so as to stay as far from every shark as possible over the tt 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 dd be the smallest such distance over all tt time steps (the closest you ever come to a shark). The distance between two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is the Euclidean distance d=(x1−x2)2+(y1−y2)2d = \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}. Your goal is to choose a move plan that makes dd as large as possible while ending up back at position (1,1)(1, 1) at time tt.

Input

The first line contains a number K≥1K \ge 1, the number of data sets in the input. It is followed by KK data sets of the following form.

The first line of each data set contains four integers ww, hh, tt, ss. Here 1≤w,h≤101 \le w, h \le 10 are the width and height of the water area, 1≤t≤1001 \le t \le 100 is the number of time steps you spend in the water, and 1≤s≤100001 \le s \le 10000 is the number of shark sightings.

This is followed by ss lines, each containing three integers xix_i, yiy_i, tit_i with 1≤xi≤w1 \le x_i \le w, 1≤yi≤h1 \le y_i \le h, and 1≤ti≤t1 \le t_i \le t. Such a line means that at time tit_i there is a shark at position (xi,yi)(x_i, y_i). 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 xx is the number of the data set (starting from 11). Then output the closest you ever come to a shark in the best possible move plan, rounded to two decimals. (An output of 0.000.00 means you cannot avoid occupying the same square as a shark at some time.)

Examples3

  1. Example 1

    Input
    2
    2 2 2 2
    1 1 2
    2 2 1
    3 3 5 5
    2 2 1
    1 2 2
    1 1 3
    1 3 3
    3 1 3
    
    Expected output
    Data Set 1:
    0.00
    Data Set 2:
    1.41
    
  2. Example 2

    Input
    1
    1 1 1 1
    1 1 1
    
    Expected output
    Data Set 1:
    0.00
    
  3. Example 3

    Input
    1
    5 5 1 1
    3 3 1
    
    Expected output
    Data Set 1:
    2.83