Casting
Time limit1sMemory limit128 MB
For a convex polygon, count the vertex pairs whose connecting line splits it into two parts that can each be pulled out by translation.
- Level
Hard9 of 10
- Topics
- Geometry, Two pointers, Math, Implementation
- Solved
- No attempts yet
Problem
Casting is a manufacturing process in which liquid is poured into a cast (mold) that has a cavity shaped like the object to be produced. The liquid hardens, after which the cast is removed. To mass produce the object by reusing the same cast parts, the cast parts must be removable from the object by translation without destroying either the cast parts or the object.
Given a convex polygon (the object), we divide the cast into two parts along a straight line through two vertices of . The goal is to choose the two vertices so that both cast parts can each be removed by translation (without destroying the cast parts or the object). For instance, in the original figures, dividing along the line through one pair of vertices lets the upper part be pulled upward and the lower part downward, while dividing along the line through some other pair leaves a part that wraps around the object and cannot be removed in any direction. Thus, not every pair of vertices admits such a division. (Each part may be removed in its own translation direction; removal is not required to be perpendicular to the dividing line.)
Given a convex polygon with vertices, write a program that finds all pairs of vertices such that both cast parts of , divided by the straight line through and , can be removed by translation.
Input
Your program reads from standard input. The first line contains the number of test cases . Each test case begins with an integer , the number of vertices of a convex polygon , where . The next line contains integers , where and are the - and -coordinates of vertex of . All coordinates are integers with . The vertices are given in clockwise order along the boundary of .
Output
Your program writes to standard output. For each test case, print a single line containing the number of pairs of vertices with such that both cast parts of , divided by the straight line through and , can be removed by translation without destroying either the cast parts or the object.