TopCoder problem "Symmetry" used in TCI '02 Round 4 (Division I Level Three)



Problem Statement

    

A line of symmetry is a line through the cartesian plane such that if you reflect everything from one side of the line to the other, you still have the same image. For example, if the x-axis is a line of symmetry, it means that for every point (x,y) there is also a point (x,-y).

Your task is, given a list of points, determine how many such lines exist.

 

Definition

    
Class:Symmetry
Method:countLines
Parameters:String[]
Returns:int
Method signature:int countLines(String[] points)
(be sure your method is public)
    
 

Constraints

-Each element of points will be formatted as a list of x,y pairs "<x1> <y1> <x2> <y2> <x3> <y3> ...", where there is exactly one space between every two terms, and both <xi> and <yi> are integers.
-<xi> and <yi> will both be between -10,000 and 10,000, inclusive.
-Each point will be unique.
-There will be between 2 and 200 points, inclusive.
 

Examples

0)
    
{"1 1 1 -1 -1 1 -1 -1"}
Returns: 4
This looks something like this (where '-' and '|' represent the axes, and '*' represents a point):
        |
        |
     *  |  *
        |
--------+--------
        |
     *  |  *
        |
        |
There are 4 lines of symmetry. Both axes are lines of symmetry, as are the line y = x and y = -x.
1)
    
{"0 0 2 1 0 5 -2 4"}
Returns: 2
2)
    
{"0 100 100 0","0 0 100 100","51 52"}
Returns: 0
3)
    
{"0 0","100 0","50 87"}
Returns: 1

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=924

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4355&pm=924

Writer:

lars2520

Testers:

Problem categories:

Geometry