This page is still under construction.

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

Foreclosure Borough

Time limit1sMemory limit128 MB

Summary
For each polygon borough, compute the percentage of houses inside it that are in foreclosure, sort boroughs by rate, and print two-decimal rates with tie-breaking by borough number.
Level

Medium5 of 10

Topics
Geometry, Sorting, Implementation
Solved
No attempts yet

Problem

You are given the locations of houses and, for each house, whether it is currently in foreclosure. You are also given several boroughs (areas), each described by a simple (non-self-intersecting) polygon. Different boroughs may overlap, so a single house can belong to more than one borough.

For every borough, compute its foreclosure rate: the percentage of the houses located inside that borough that are in foreclosure. Then report the boroughs sorted by this rate.

Input

The first line contains the number of data sets KK. Each data set has the following form:

  • The first line contains two integers HH and BB: the number of houses (1≤H≤10001 \le H \le 1000) and the number of boroughs (1≤B≤1001 \le B \le 100).
  • Each of the next HH lines describes one house: its xx and yy coordinates (floating-point numbers) followed by a single character, Y if the house is in foreclosure or N if it is not.
  • Each of the next BB lines describes one borough. The line begins with an integer c≥3c \ge 3, the number of polygon corners, followed by 2c2c floating-point numbers x1 y1 x2 y2 … xc ycx_1\ y_1\ x_2\ y_2\ \dots\ x_c\ y_c giving the corners in counter-clockwise order.

No house lies exactly on the boundary of a borough, and every borough contains at least one house.

Output

For each data set, first print a line Data Set x:, where xx is the 1-based index of the data set. Then print one line for each of the BB boroughs.

Each borough line has the form b: r%, where bb is the borough number (its 1-based position in the input) and rr is its foreclosure rate as a percentage, rounded to exactly two decimal places (round half up).

Sort the borough lines by non-increasing foreclosure rate; break ties by the smaller borough number. Print an empty line between consecutive data sets.

Examples1

  1. Example 1

    Input
    1
    8 3
    0 0 Y
    0 1 N
    1 0.5 N
    0.7 0.7 Y
    -0.5 0 N
    -5 0 N
    0.7 0 Y
    3.4 0.95 N
    3 -1 -0.5 1 -0.5 -1 0.75
    4 -0.2 -0.5 1 -0.2 3 1.5 -0.2 1.5
    5 0.5 0 1.5 -0.2 4 1.2 1 0 0.5 1.5
    
    Expected output
    Data Set 1:
    3: 66.67%
    2: 60.00%
    1: 50.00%