Transmitters
InterviewTime limit1sMemory limit128 MB
Given a fixed center, a radius, and up to 150 points, find the largest number of points that fit inside some semicircular half-disk at any rotation.
- Level
Medium7 of 10
- Topics
- Geometry, Two pointers, Sorting, Brute force
- Solved
- No attempts yet
Problem
In a wireless network where several transmitters share the same frequencies, their signals must not overlap or conflict. One way to achieve this is to limit a transmitter's coverage area. This problem uses a shielded transmitter that broadcasts only over a semicircle.
A transmitter sits at a fixed location on a grid. It broadcasts over a semicircular region of radius (a half-disk centered at ). The transmitter may be rotated by any angle about its position, but it cannot be moved. Given points on the grid, determine the maximum number of points that the transmitter's signal can cover at the same time. The figure below shows one set of points reached under two different rotations of the transmitter.

Input
The input contains one or more independent transmitter scenarios.
Each scenario starts with a line holding the transmitter's coordinates and followed by the broadcast radius . The next line contains the number of points , followed by lines, each giving the and coordinates of one point.
All point coordinates are integers between and . The radius is a positive real number. A point lying exactly on the boundary of the semicircle (its straight edge or its arc) counts as covered. Each scenario has between and distinct points, and no point coincides with the transmitter.
The input ends with a line whose radius is negative; on that final line the and values are present but meaningless.
Output
For each transmitter scenario, print a single line containing the maximum number of points that can lie within some semicircle.