This page is still under construction.

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

Laser Lines

Time limit1sMemory limit128 MB

Summary
For each coordinate set, find every straight line through three or more points and print the collinear points in sorted order.
Level

Medium6 of 10

Topics
Geometry, Hash map, Sorting
Solved
No attempts yet

Problem

A computer-chip manufacturer has found a new way to combine opto-electronics with ordinary electronics by placing light-emitting and light-receiving nodes on the surface of a chip. The nodes exchange messages along direct lines of sight, which greatly speeds up operation by allowing a much higher density of information transfer.

The difficulty is that every node must be able to send a message to every other node: no node may block the line of sight between two other nodes. The manufacturing process guarantees that each node sits exactly on a lattice point of the chip, so its coordinates are integers between 0 and 9999 inclusive. For technical reasons no node is ever placed at the point (0, 0).

Read several sets of node coordinates and, for each set, determine whether any nodes lie on a straight line that passes through three or more nodes. Lines through exactly three nodes may be common, while longer lines become increasingly rare; no line will ever contain more than 10 nodes.

Input

The input is a series of data sets. Each set lists the coordinates of between 3 and 300 points (inclusive). The coordinates are pairs of integers in the range 0 to 9999, and each set is terminated by the pair 0 0. Numbers are separated by one or more spaces, and a single set may be spread across several lines; a line break only ever occurs between coordinate pairs, never between the two numbers of one pair. After the final data set, the whole input is terminated by one more pair 0 0. There are several data sets, but only one of them contains more than 100 points.

Output

For each data set, print exactly one of the following.

  • No lines were found, when no straight line passes through three or more points.
  • The following lines were found: (with a single trailing space), followed by one line for every straight line that passes through three or more points.

On each such line, list the points that lie on it, sorted by x and, when the x-coordinates are equal, by y. Every coordinate is written in a field of width 4 (right-justified, padded with spaces); the two coordinates of a point are separated by a comma and enclosed in parentheses (a single point looks like ( 4, 8)), and successive points are written directly next to one another with no spaces in between. The lines are ordered the same way the points on a line are: first by the first point of each line, and, when several lines share that first point, by the second point, and so on.

Examples4

  1. Example 1

    Input
      5 5 8 7 14 11 4 8   20 15
    12 6  18 21 0  0
    5 5 8 8 14 13 0 0
    5 5 25 17 20 23 10 11 20 14 15 11 0 0
    0 0
    
    Expected output
    The following lines were found: 
    (   4,   8)(   8,   7)(  12,   6)
    (   5,   5)(   8,   7)(  14,  11)(  20,  15)
    (  12,   6)(  14,  11)(  18,  21)
    No lines were found
    The following lines were found: 
    (   5,   5)(  10,  11)(  20,  23)
    (   5,   5)(  15,  11)(  20,  14)(  25,  17)
    
  2. Example 2

    Input
    3 3 1 1 2 2 0 0
    0 0
    
    Expected output
    The following lines were found: 
    (   1,   1)(   2,   2)(   3,   3)
    
  3. Example 3

    Input
    1 1 2 2 3 4 0 0
    0 0
    
    Expected output
    No lines were found
    
  4. Example 4

    Input
    1 2 2 4 3 6 5 5 0 0
    7 1 8 2 9 4 0 0
    0 0
    
    Expected output
    The following lines were found: 
    (   1,   2)(   2,   4)(   3,   6)
    No lines were found