What are Birds? (Small)
Time limit5sMemory limit512 MB
Given labeled bird and non-bird points in 2D, decide for unlabeled animals whether they must be birds, cannot be birds, or are unknown.
- Level
Medium5 of 10
- Topics
- Intervals, Implementation, Math
- Solved
- No attempts yet
Problem
You are studying animals in a forest and want to decide which of them are birds.
For every animal you measure two numbers, its height and its weight. An animal is a bird exactly when its height lies inside one range and its weight lies inside another range. You do not know either range. Every animal that satisfies both ranges is a bird, without exception.
You showed some of the measured animals to biologists, and they told you which ones are birds. Those answers restrict what the height range and the weight range can be. For each animal you did not show them, decide whether it is certainly a bird, certainly not a bird, or undecided from the information you have.
The biologists are always right, so at least one pair of ranges agrees with every answer they gave.
Input
The first line contains an integer , the number of test cases.
Each test case is given as follows.
- One line with an integer , the number of animals shown to the biologists.
- lines, one per animal, in the form
H W X, where is the height, is the weight, and is eitherBIRDorNOT BIRD. - One line with an integer , the number of animals not shown to the biologists.
- lines, one per animal, in the form
H W, the height and the weight.
Limits
- Every height and weight is an integer with .
Output
For each test case print lines.
- One line with
Case #X:, where is the number of the test case, counting from 1. - lines with the verdict for each animal you did not show, in input order. Print
BIRDif the animal must be a bird,NOT BIRDif it cannot be a bird, andUNKNOWNif both are still possible.
Notes on the example
In case 1 of the example, the animal 1500 1500 must be a bird, because the height range and the weight range each contain 1000 and 2000. The animal 900 900 may or may not be a bird, since nothing tells you whether 900 falls inside either range. The animal 1400 2020 lies inside the height range, but if 2020 were inside the weight range, then 1500 2010, which is known not to be a bird, would also fall inside both ranges. So 1400 2020 is not a bird.
In case 2 you know that a bird must have height 501. About the weight range you only know that it contains 700.
In case 3 you know that an animal of height 100 and weight 100 is not a bird, and nothing more.