Electrical Engineering

Time limit1sMemory limit128 MB

Summary
For each query point, find the strongest signal among routers whose segment to the point crosses no polygon wall, using 1/d^2 falloff.
Level

Medium5 of 10

Topics
Geometry, Brute force, Implementation, Math
Solved
No attempts yet

Problem

Electrical engineers study how electrical and electronic devices are built and how they communicate with one another. A popular topic is wireless networking. Here we look at a simplified model of providing wireless coverage to an area.

The area is a polygon given by a sequence of corners, and every edge of the polygon acts as a wall. Inside (or around) the area there are one or more wireless routers. Signal strength is modeled as follows.

  • If a wall lies on the straight segment between a router and a location, that router gives the location no signal at all (strength 00).
  • If there is no wall, the signal strength from that router is 1/d21/d^2, where dd is the distance between the router and the location.
  • If a location receives a signal from several routers, only the strongest signal is counted.

For several query locations, report the resulting signal strength.

This model ignores reflection of signals off walls and penetration through walls.

Input

The first line contains an integer K≥1K \ge 1, the number of data sets. Each data set has the following form.

The first line of a data set contains three integers nn, rr, pp: the number of polygon corners, the number of routers, and the number of query points. All three values are between 11 and 100100.

  • The next nn lines each contain a corner as two floating-point numbers xx yy, listed in order around the polygon.
  • The next rr lines each contain a router location xx yy.
  • The final pp lines each contain a query point xx yy.

You may assume that (1) no router or query point lies exactly on a wall, (2) no router coincides with a query point, and (3) the segment from a router to a query point never merely touches a wall — it either properly crosses the wall or avoids it completely.

Output

For each data set, first print Data Set x: on a line by itself, where xx is the data set number, starting from 11. Then, for each of the pp query points, print on a line by itself the maximum signal strength at that point, rounded to two decimal places.

Examples1

  1. Example 1

    Input
    1
    5 3 3
    0 0
    1 0
    1 1
    0.5 0.5
    0 1
    0.1 0.1
    0.9 0.1
    0.4 0.55
    0.1 0.5
    0.6 0.55
    0.5 0.6
    
    Expected output
    Data Set 1:
    10.81
    3.42
    0.00