Symmetry
TCI '02 Round 4 · 2002-10-30 · by lars2520
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.
Constraints
- Each element of points will be formatted as a list of x,y pairs "
...", where there is exactly one space between every two terms, and both and are integers. and will both be between -10,000 and 10,000, inclusive. - Each point will be unique.
- There will be between 2 and 200 points, inclusive.
{"0 100","100 0","0 0","100 100","51 51"}
Returns: 1
{"0 100","100 0","0 0","100 100","51 50"}
Returns: 1
{"0 100","100 0","0 0","100 100","50 50"}
Returns: 4
{"0 100","100 0","0 0","100 100","51 52"}
Returns: 0
{"1 0","0 1","-1 0","0 -1"}
Returns: 4
{"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.
Submissions are judged against all 32 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Symmetry with a public method int countLines(vector<string> points) · 32 test cases · 2 s / 256 MB per case