#P3699. Connecting Key Points on Scratch Paper
Connecting Key Points on Scratch Paper
Connecting Key Points on Scratch Paper
Q is a programmer. On his scratch paper – which is modeled as a two‐dimensional plane with a Cartesian coordinate system – previous drafts have rendered some areas unusable. Each such used area is given as a triangle (with its interior and boundary unavailable for further drawing) and no two used triangles overlap.
Q has already placed several key points on the unused area of the paper. He now wishes to connect as many pairs of these key points as possible with straight line segments. However, a line segment connecting two key points is valid only if it does not intersect (even touch) any of the previously used triangular regions. It is guaranteed that no three key points are collinear, and none of the key points lies inside or on any of the triangles.
More formally, given n key points and m triangles, count the number of pairs of key points that can be connected by a line segment which does not intersect any edge (or the interior) of any triangle. For a triangle with vertices \( (x_1,y_1)\), \( (x_2,y_2)\), and \( (x_3,y_3)\), its edges are the line segments joining each pair of vertices. A line segment connecting two key points is invalid if it intersects or touches any of these edges.
Note: The intersection of a segment with a triangle means that there exists a point (other than the endpoints if they are outside) that lies both on the segment and on the boundary or interior of a triangle.
inputFormat
The input begins with a line containing two integers ( n ) and ( m ) (( 2 \le n \le 500 ), ( 0 \le m \le 500 )), representing the number of key points and the number of used triangular areas, respectively. The next ( n ) lines each contain two floating-point numbers denoting the coordinates of a key point. Each of the following ( m ) lines contains six floating-point numbers ( x_1\ y_1\ x_2\ y_2\ x_3\ y_3 ) which represent the coordinates of the vertices of a triangle. It is guaranteed that none of the key points lies in or on any triangle, and no three key points are collinear.
outputFormat
Output a single integer: the number of pairs of key points that can be connected by a valid line segment.
sample
3 0
0 0
1 1
1 0
3