#P12811. [AMPPZ 2019] Antennas
[AMPPZ 2019] Antennas
Description
In a secret military base, a new communication technology is being tested. For the experiment, antennas were constructed inside.
The terrain around the base is perfectly flat, and the base, seen from above, is a convex polygon. The boundary of the polygon is a wall that protects the base from intruders, as well as blocks the radio waves from leaving the base to be possibly intercepted by foreign agents.
Unfortunately, some construction works are required in the facility, and two of the polygon’s walls must be torn down. This creates a security risk: if two spies are placed outside the base in such a way that two of the antennas lie on the line between them, and there is no wall blocking this line, then the spies may listen to the communication between those two antennas.
Your goal is, for some possible scenarios of removal of two walls, to determine the number of
pairs of antennas which are compromised in the way described above.

The picture above corresponds to the first case of the example input from the “Example” section. In this case, the base is a pentagon with four antennas, denoted by little crosses. All the lines between pairs of antennas are also shown.
Input Format
The first line of input contains the number of test cases (). The test cases
follow, each one in the following format:
The first line of a test case contains an integer () – the number of vertices of
the polygon. The next lines contain two integers – the coordinates of the vertices, presented
clockwise. The vertices are numbered in order in which they appear.
The next line contains an integer () – the number of antennas inside the
base – and the following lines contain the coordinates of the antennas.
The next line contains another integer () – the number of scenarios to consider.
The last lines describe scenarios – the -th line contains two integers , ().
Such a pair denotes removing the walls and and requires to compute the number of distinct
lines that go through some two antennas and do not cross neither the segment between the vertices and nor the segment between and .
All coordinates are integers whose absolute values do not exceed . In any single testcase, all points of the input are distinct and no three of them are collinear.
Every test case, including the first, is preceded by a single empty line.
The sum of all values in all test cases does not exceed .
Output Format
For every testcase output, in separate lines, the answers to all given scenarios.
2
5
0 0
0 5
3 7
6 5
6 0
4
1 2
1 3
5 2
5 3
3
0 3
1 4
1 2
4
-1 -1
-1 1
2 1
2 -1
2
0 0
1 0
6
0 1
0 2
0 3
1 2
1 3
2 3
4 1 0
0 1 0 0 0 0
京公网安备 11011102002149号