This page is still under construction.

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

Stars

Time limit1sMemory limit128 MB

Summary
Count and find the brightest occurrence of each constellation pattern as a direct similarity transform of integer points within a star map.
Level

Hard8 of 10

Topics
Geometry, Hash map, Brute force, Sorting
Solved
No attempts yet

Problem

On a clear, moon-less night you can see millions of stars glimmering in the sky. Faced with this overwhelming number, the Greeks began nearly 2,000 years ago to bring some order to the chaos. They identified groups of stars, called constellations, and gave them names — mostly from Greek mythology — that are still in use today. Examples are "Ursa Minor", "Pisces", "Cancer", and many others.

Given a sketch of a constellation, it is not easy for an amateur to actually find it in the sky. Moreover, simple constellations — such as "Triangulum" (a triangle), which consists of only three stars — may appear several times, and singling out the "correct" occurrence is hard. In this problem we let the computer find constellations in the sky.

You are given a star map: a collection of points in the plane, each with an associated brightness. You are also given several constellations, each a set of points in the plane. For every constellation you must determine:

  • the number of times it occurs in the star map, and
  • the greatest brightness of any occurrence, if at least one exists.

An occurrence is a subset of stars from the map that forms a copy of the constellation obtained by translation, rotation, and uniform (positive) scaling only — that is, a direct, orientation-preserving similarity. Reflections (mirror images) are not allowed. Two occurrences are considered the same if and only if they consist of exactly the same subset of map stars.

The total brightness of an occurrence is the sum of the brightnesses of the stars it consists of. Because every occurrence of a given constellation contains the same number of stars, the occurrence with the greatest total brightness is also the one with the greatest average brightness; we report that maximum total brightness.

Input

The input contains the descriptions of several star maps. Each map starts with a line containing a single integer nn, the number of stars in the map (1≤n<10001 \le n < 1000). Each of the following nn lines contains three integers: the xx-coordinate, the yy-coordinate, and the brightness of one star. The larger the value, the brighter the star.

The next line contains a single integer mm, the number of constellations that follow (1≤m<501 \le m < 50). Each constellation description starts with a line containing an integer sis_i, the number of stars in constellation ii, followed by a string NiN_i, the name of the constellation (NiN_i has at most 40 characters and contains no blanks). The following sis_i lines each contain the xx- and yy-coordinates of one point of the constellation.

A blank line separates one star map from the next. The input ends with an empty map (n=0n = 0), which must not be processed.

Because all star coordinates are integers, any rotated or scaled placement of a constellation whose points would not fall on integer coordinates can immediately be ruled out.

Output

For each star map, first output the number of the map ("Map #1", "Map #2", and so on) on a line of its own.

For each constellation, in the same order as in the input, output a blank line, then a line stating its name and how many times it occurs in the map, in the form:

<name> occurs <k> time(s) in the map.

If the constellation occurs at least once, output on the next line the greatest total brightness of any of its occurrences, in the form:

Brightest occurrence total brightness: <B>

If it does not occur, output no brightness line for it.

After the last constellation of a star map, output a line consisting of exactly five dashes ("-----").

Examples3

  1. Example 1

    Input
    6
    1 2 1
    2 1 4
    2 4 3
    3 2 1
    4 1 5
    4 3 2
    2
    3 Triangulum
    1 1
    3 1
    2 4
    4 Cancer
    1 3
    4 3
    6 1
    7 5
    
    0
    
    Expected output
    Map #1
    
    Triangulum occurs 2 time(s) in the map.
    Brightest occurrence total brightness: 8
    
    Cancer occurs 0 time(s) in the map.
    -----
    
  2. Example 2

    Input
    3
    0 0 5
    10 10 2
    5 5 9
    1
    1 Dot
    0 0
    0
    
    Expected output
    Map #1
    
    Dot occurs 3 time(s) in the map.
    Brightest occurrence total brightness: 9
    -----
    
  3. Example 3

    Input
    4
    0 0 1
    1 0 7
    0 1 9
    1 1 3
    1
    2 Pair
    0 0
    5 0
    0
    
    Expected output
    Map #1
    
    Pair occurs 6 time(s) in the map.
    Brightest occurrence total brightness: 16
    -----