Finding Rectangles
Time limit1sMemory limit128 MB
List every axis-aligned rectangle that can be formed from up to 26 labeled points, printing the four vertex labels in clockwise order.
- Level
Medium4 of 10
- Topics
- Brute force, Geometry, Sorting, Implementation
- Solved
- No attempts yet
Problem
Consider the point sets in figures 1a, 2a, and 3a. Using only those points as vertices, figures 1b, 2b, and 3b show every rectangle that can be formed with horizontal and vertical sides. No rectangle can be formed from the points in figure 4.

Write a program that finds every rectangle with horizontal and vertical sides (that is, axis-aligned) that can be formed from a given set of labeled points. The example cases below correspond to the figures above.
Input
The input contains one or more point sets, followed by a line containing a single that marks the end of the input.
Each point set begins with a line containing , the number of points, followed by lines that describe the points. Each point description contains a capital letter (the label of the point), a space, the horizontal coordinate, a space, and the vertical coordinate.
Within each set the point labels appear in alphabetical order. Because each point is labeled with a capital letter, a set contains at most 26 points. All coordinates are nonnegative integers less than 50, and the points within a set are distinct.
Output
For each point set, print Point set followed by the number of the point set and a colon.
If the set contains no rectangles, print No rectangles (with a single leading space) after the colon, on the same line.
Otherwise the rectangles are listed starting on the next line. A single space precedes each rectangle. Each rectangle is given by its four vertex labels in clockwise order starting from the upper-left corner, that is upper-left, upper-right, lower-right, lower-left (a larger vertical coordinate is higher). The rectangles are printed ten per line, except possibly the last line, and are listed in alphabetical order.