This page is still under construction.

Parts of this page are still being built. What you see may change.

Transmitters

Interview

Time limit1sMemory limit128 MB

Summary
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 TT sits at a fixed location on a 1000×10001000 \times 1000 grid. It broadcasts over a semicircular region of radius rr (a half-disk centered at TT). The transmitter may be rotated by any angle about its position, but it cannot be moved. Given NN 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 xx and yy followed by the broadcast radius rr. The next line contains the number of points NN, followed by NN lines, each giving the xx and yy coordinates of one point.

All point coordinates are integers between 00 and 10001000. The radius rr 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 11 and 150150 distinct points, and no point coincides with the transmitter.

The input ends with a line whose radius is negative; on that final line the xx and yy 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.

Examples1

  1. Example 1

    Input
    25 25 3.5
    7
    25 28
    23 27
    27 27
    24 23
    26 23
    24 29
    26 29
    350 200 2.0
    5
    350 202
    350 199
    350 198
    348 200
    352 200
    995 995 10.0
    4
    1000 1000
    999 998
    990 992
    1000 999
    100 100 -2.5
    
    Expected output
    3
    4
    4