A Highway and the Seven Dwarfs
Time limit1sMemory limit128 MB
Given N points and many query lines, report for each line whether all points fall strictly on one side or the line splits them into two groups.
- Level
Medium7 of 10
- Topics
- Geometry, Divide and conquer, Sorting, Binary search
- Solved
- No attempts yet
Problem
Long ago there was a land called Dwarfland, home to several families of dwarfs. Each family lived in one house, and the dwarfs loved visiting their friends in the other houses.
The humans in the surrounding countries decided to build several straight highways. Some of the planned highways would pass through Dwarfland. The dwarfs are tiny and slow, so they cannot cross a highway safely. If a highway separates the houses into two non-empty groups, some dwarfs can no longer reach their friends. A highway is therefore harmless only if it does not split the houses into two groups.
You are given points (houses) in the plane and several straight lines (highways). For each line, decide whether all houses lie on the same side of the line, or whether the line divides them into two groups. No highway passes through any house.
Input
The first line contains an integer (), the number of houses.
Each of the next lines contains two real numbers and (), separated by a space — the coordinates of the -th house.
Each remaining line contains four real numbers , , , (), separated by spaces. They are the coordinates of two distinct points and lying on one highway. There are at most highways, and the input ends at end-of-file.
Output
For each highway, print a single line: GOOD if all houses lie on the same side of the line, or BAD if the line splits the houses into two non-empty groups.
Because the coordinates are real numbers, rounding errors may occur; when checking whether two computed real values are equal, allow a small tolerance (for example ).