Radioactivity
Time limit1sMemory limit128 MB
For each pair of radiation radii, count houses not covered by either plant after houses in both zones donate a spare unit.
- Level
Medium7 of 10
- Topics
- Geometry, Sorting, Binary search, Prefix sum
- Solved
- No attempts yet
Problem
A nuclear power plant is both a blessing and a curse of modern civilization. It carries many dangers, yet it is also the cheapest way to generate electricity. In this problem we consider the situation created by two nuclear power plants that stand close to each other.
Assume the ground is completely flat and every house lies on a 2D coordinate plane. The two plants are located at and . Any location whose distance from plant is at most (the boundary at distance exactly is included) is a high-risk radiation zone. Likewise, any location whose distance from plant is at most is also a high-risk radiation zone.
The plant operators hand out one piece of protective equipment to each house in a high-risk zone. Therefore a house that lies in the high-risk zones of both plants receives two pieces. However, a single piece is already enough to keep a house safe.
A house outside every high-risk zone belongs to the low-risk zone and initially receives no equipment. A house holding two pieces may give its spare to a low-risk house, so that the low-risk house also has one piece. Even after this redistribution, some houses may still end up with no equipment.
Given the positions of the houses, the positions of the two plants, and several possible pairs, write a program that, for each pair, computes the number of houses that end up without protective equipment.
Input
The input consists of at most 3 test cases. Each test case has the following format.
- The first line contains the number of houses . ()
- The next lines each contain the coordinates of a house. () No two houses share the same location.
- The next line contains . (, ) and are the coordinates of the two plants, and is the number of pairs to check.
- The next lines each contain . ()
After all test cases, a final line contains a single .
Output
For each test case, print lines. The first line prints the test case number in the form Case k: ( starts from 1). The following lines print, in the input order of the pairs, the number of houses that end up without protective equipment.