Tiling Verification
Time limit1sMemory limit128 MB
Given a floor and up to 100 rectangles, decide whether they overlap, stick out of the floor, or fail to cover it, printing which condition fails first.
- Level
Medium5 of 10
- Topics
- Geometry, Implementation, Sorting, Brute force
- Solved
- No attempts yet
Problem
You want to cover a rectangular floor completely with rectangular tiles. Given several floors, write a program that, for each floor, checks whether the tiles placed on it satisfy all three of the following conditions:
- The tiles are pairwise disjoint (they do not overlap).
- No tile extends outside the floor.
- The tiles cover the entire floor.
All coordinates are integers, and every tile has positive area. The lower-left corner of the floor is the origin , and its upper-right corner is . Each tile is the rectangle whose lower-left corner is and whose upper-right corner is .
Input
The first line contains the number of floors.
Each floor is described over several lines. The first line contains two positive integers, the length and width of the floor in millimeters; each of the length and width is at most . The next line contains the number of tiles (). Each of the following lines describes one tile as four integers
xl yl xh yh
where is the lower-left corner and is the upper-right corner of the tile. The coordinate axes of the floor and the tiles coincide.
Output
For each floor, print exactly one of the following words on its own line:
NONDISJOINT: if some tiles overlap;NONCONTAINED: if no tiles overlap, but some tile extends outside the floor;NONCOVERING: if no tiles overlap and no tile extends outside the floor, but some part of the floor is left uncovered;OK: if none of the above holds.