Guard

Time limit1sMemory limit128 MB

Summary
Place g guards on segments so every valuable point is seen, minimizing the largest value-times-distance risk, or report too few guards.
Level

Hard9 of 10

Topics
Geometry, Binary search, Greedy, Implementation
Solved
No attempts yet

Problem

A security company posts guards to protect valuable items placed along a set of straight corridors. Each corridor is modeled as a line segment of zero width. Items sit at labeled points, and every point carries a non-negative integer value (a value of 00 means there is no valuable item there).

A guard may stand at any point along a corridor, including at an intersection where several corridors cross. A guard can see, and therefore protect, every item that lies on a corridor passing through the guard's own position. A guard cannot see around a corner: if an item lies on a different corridor that does not pass through the guard's position, that guard does not protect it, no matter how close it is in a straight line.

The risk to a valuable item equals its value multiplied by the distance to the nearest guard that can see it.

risk=value×min⁡guards that see the itemdist(guard,item)\text{risk} = \text{value} \times \min_{\text{guards that see the item}} \text{dist}(\text{guard}, \text{item})

Given a site layout and a number of guards gg, place the gg guards so that the maximum risk over all valuable items is as small as possible, and report that minimized maximum risk. If the gg guards cannot be positioned so that every valuable item is seen by at least one guard, report that there are too few guards.

Input

The input contains from one to sixteen datasets, followed by a line containing a single 00.

The first line of each dataset holds three integers pp cc gg: the number of labeled points, the number of corridors, and the number of guards to place, with 1<p<121 < p < 12, 0<c<120 < c < 12, and 0<g<50 < g < 5.

Next come pp groups of four tokens LL xx yy vv: a point labeled LL at coordinates (x,y)(x, y) that holds an item of value vv. Labels are consecutive capital letters starting at AA. All numbers are less than 10001000. Every point is distinct. A value of v=0v = 0 means there is no valuable item at that point. The number of points that hold a valuable item is at least gg.

Finally, cc tokens follow, one per corridor. Each token is a string of point labels listing, in order from one end of the corridor to the other, every point on that corridor: both endpoints, every intersection with another corridor, and every valuable item on it. Every point of the dataset lies on at least one corridor.

Output

Print one line per dataset. If the gg guards cannot be placed so that every valuable item is seen by some guard, print too few guards. Otherwise print the minimized maximum risk rr — the smallest possible value, over all placements of the gg guards, of the largest risk to any single valuable item — rounded to exactly two digits after the decimal point.

Examples1

  1. Example 1

    Input
    11 5 3
    A 0 8 4 B 5 8 0 C 14 8 4 D 21 8 2 E 25 8 1 F 5 22 1
    G 5 20 0 H 11 12 50 I 20 0 50 J 19 10 5 K 25 4 5
    ABCDE AG FGB GHCI JDK
    11 5 2
    A 0 8 4 B 5 8 0 C 14 8 4 D 21 8 2 E 25 8 1 F 5 22 1
    G 5 20 0 H 11 12 50 I 20 0 50 J 19 10 5 K 25 4 5
    ABCDE AG FGB GHCI JDK
    11 5 1
    A 0 8 4 B 5 8 0 C 14 8 4 D 21 8 2 E 25 8 1 F 5 22 1
    G 5 20 0 H 11 12 50 I 20 0 50 J 19 10 5 K 25 4 5
    ABCDE AG FGB GHCI JDK
    11 5 4
    A 0 8 4 B 5 8 0 C 14 8 4 D 21 8 2 E 25 8 1 F 5 22 1
    G 5 20 0 H 11 12 50 I 20 0 50 J 19 10 5 K 25 4 5
    ABCDE AG FGB GHCI JDK
    3 3 1
    A 0 0 50 B 0 3 60 C 4 0 20
    AB CB CA
    0
    
    Expected output
    375.00
    1250.00
    too few guards
    21.21
    150.00