Space Base Construction
InterviewTime limit1sMemory limit128 MB
For each query rectangle, decide if its center lies on some platform or if at least three of its four corners lie on platforms.
- Level
Medium7 of 10
- Topics
- Geometry, Binary search, Sorting
- Solved
- No attempts yet
Problem
The Byteotian Space Agency is building a space base on the planet Bajmars. In the first stage, flat rectangular platforms were raised on metal supports above the planet's heavily eroded surface. Every platform sits at the same height, and no two platforms overlap (they may touch along their edges).
In the second stage, various objects are to be placed on these platforms. Each object is a rectangular box described by the rectangle of its base. For every planned object you must decide whether it can stand stably.
An object does not have to rest on the platforms with its entire base. It stands stably on one or more platforms when either of the following holds:
- its center of gravity lies above the surface of a single platform (a platform's border counts as part of its surface), or
- at least three of its four base corners rest on platforms.
You may assume the center of gravity lies directly above the point where the diagonals of the base meet, that is, the center of the base rectangle. A corner rests on a platform when it lies inside the platform or on its border, and different corners may rest on different platforms. It does not matter how much of the object hangs over empty space, and it does not matter if the planned objects overlap one another, because these are only plans.
Write a program that reads the platform coordinates and the proposed placements, and for each object reports whether it stands stably.
Input
The first line contains the number of platforms , . Each of the next lines describes one platform with four integers : the coordinates of its lower-left and upper-right corners, where and .
The next line contains the number of planned objects , . Each of the next lines describes one plan with four integers : the lower-left and upper-right corners of that object's base, with the same bounds.
Output
Print exactly lines. The -th line is TAK if the -th object can be placed stably, or NIE otherwise.
Hint
