Strictly Inscribed Similar Triangles
Time limit1sMemory limit128 MB
For each triangle and angle theta, count how many strictly inscribed triangles similar in order to the given triangle exist with a chosen edge at that angle.
- Level
Hard8 of 10
- Topics
- Geometry, Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
Two triangles and are similar if their corresponding sides are proportional (equivalently, if their corresponding angles are equal). We say that and are similar in order if corresponds to , corresponds to , and corresponds to . That is,
where denotes the length of the segment from to .
Triangle is strictly inscribed in triangle if each vertex of lies in the interior (not at a vertex) of a different edge of . This means no edge of can be contained in an edge of . If is similar in order to and strictly inscribed in , we call a strictly inscribed similar triangle of .
If the line through and makes an angle with the line through and , there are four possible orientations, illustrated below: and may be at either end of the segment, and the third vertex may be on either side of the line. In the figure, the line through and makes an angle of with the line through and .

Depending on the shape of the outer triangle and the angle between the line through and and the line through and , there may be 0, 1, 2, 3, or 4 strictly inscribed similar triangles of with angle .
Given the vertices of triangle and an angle , determine how many strictly inscribed similar triangles of exist for which the line through and makes an angle with the line through and .
Input
The first line contains a positive integer , the number of triangle datasets that follow. Each dataset consists of four lines: the first line has the and coordinates of vertex , the second line has the and coordinates of vertex , the third line has the and coordinates of vertex , and the fourth line has the angle (in degrees) between the line through and and the line through and .
Output
For each dataset, output a single line containing one integer: the number of strictly inscribed similar triangles of for which the line through and makes an angle with the line through and .