Separating Lines
Time limit1sMemory limit128 MB
For each of up to 100000 query lines, report whether the given points fall on both sides of it or touch it.
- Level
Medium7 of 10
- Topics
- Geometry, Binary search, Sorting
- Solved
- No attempts yet
Problem
You are given pairwise distinct points and lines on the plane.
A line divides the plane into two half-planes. Both of them are closed, which means the line itself belongs to each of the two half-planes. A line is called separating when each of the two half-planes it creates contains at least one of the given points.
For every given line, decide whether it is separating.
Because a point lying exactly on the line belongs to both half-planes, a line that passes through at least one of the points is always separating. In other words, a line fails to be separating only when every point lies strictly on the same side of it, with no point on the line.
Input
The first line contains an integer (), the number of test cases. Each test case is given as follows.
The first line contains an integer (), the number of points. Each of the next lines contains two integers and (), the coordinates of one point. All points are pairwise distinct.
The next line contains an integer (), the number of lines. Each of the next lines contains four integers , , , (), the coordinates of two distinct points that the line passes through.
Output
For each of the lines, print TAK (yes) if it is separating, or NIE (no) otherwise. Print each answer on its own line.