TopcoderArchive
Archive
Algorithm problem

Perimeter

Problem statement, definition, constraints, and public examples.

Problem Statement

We must cover the perimeter of a rectangular area with n sensors. The sensors are identical, and each sensor covers a circular area. The sensors may be placed anywhere.

The rectangle has width w and height h. Given n, w, and h, determine the minimum sensor radius that will allow us to cover the rectangle's perimeter.

Definition

Class:
Perimeter
Method:
minRadius
Parameters:
int, int, int
Returns:
double
Method signature:
double minRadius(int n, int w, int h)
(be sure your method is public)

Notes

  • A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.

Constraints

  • n will be between 1 and 5, inclusive.
  • w and h will each be between 1 and 1000, inclusive.

Examples

  1. 5
    1
    1000
    Returns: 100.00124999218755
    The best sensor placement is evenly spaced along the long central axis.
  2. 1
    100
    100
    Returns: 70.71067811865473
    Put the sensor at the center of the rectangle, so the answer is 50*sqrt(2).
  3. 4
    100
    100
    Returns: 35.355339059327335
    Divide the rectangle in quarters and place each sensor in the middle of one of the quarters. The return value is 25*sqrt(2).
  4. 5
    622
    531
    Returns: 182.23311960891868
Back to all problems