Under construction

Still being built. Things may change

Requiescat in Pace

Interview

Time limit1sMemory limit1024 MB

Summary
Given candidate points and line segments for trails and roads, find the candidate whose distance to the nearest segment is largest.
Level

Easy3 of 10

Topics
Geometry, Brute force
Solved
No attempts yet

Problem

After P-22’s death, there was considerable discussion about what should happen to his remains. At first, storing them in the Natural History Museum (across from USC) was proposed. In the end, a native tribe decided to give him a ritualistic burial at an undisclosed location in the Santa Monica Mountains. We do not know exactly how they chose the spot. They probably collected a few candidate locations first, then picked the best one according to one or more criteria. A natural criterion is to be far from all roads and hiking trails, so that the burial site is less likely to be disturbed. P-22 also mostly avoided people while alive. Here, you will choose such a candidate location.

All trails and roads are given as straight line segments. Curved roads can be approximated by a sequence of such segments. You are also given the candidate burial locations. Select the candidate that maximizes the minimum distance to any point on any trail or road.

Input

The first line contains the number 1≤K≤1001 ≤ K ≤ 100 of data sets, followed by the KK data sets, each of the following form.

The first line of each data set contains two integers 1≤T,L≤10001 ≤ T, L ≤ 1000, the number of trails and the number of candidate locations. Then follow LL lines, each with two real numbers xi(s)x_i^{(s)} and yi(s)y_i^{(s)}, the location of the ii-th candidate burial site. Then follow TT lines, each with four real numbers xj(t,1)x_j^{(t,1)}, yj(t,1)y_j^{(t,1)}, xj(t,2)x_j^{(t,2)}, and yj(t,2)y_j^{(t,2)}. The jj-th trail or road goes straight from (xj(t,1),yj(t,1))(x_j^{(t,1)}, y_j^{(t,1)}) to (xj(t,2),yj(t,2))(x_j^{(t,2)}, y_j^{(t,2)}). All coordinates are between −1000000.0-1000000.0 and 1000000.01000000.0.

Output

For each data set, print “Data Set xx:” on a line by itself, where xx is the data set number. Then print the index ii of the burial site whose distance to its closest point on a trail is largest. Inputs never have ties or near-ties, meaning no two distances to the closest trail differ by less than 0.0010.001. Print a blank line after each data set.

Examples1

  1. Example 1

    Input
    1
    4 3
    0 0
    1.5 1.5
    -2.5 -0.5
    -10 1.6 10 1.6
    -1 -1 1 1
    -2.5 0.5 2.5 0.5
    -3.7 -1 0.5 -0.5
    
    Expected output
    Data Set 1:
    3