TopcoderArchive
Archive4 May 2019
TCC19 India Qualifiers

ThreeTrees

Problem statement, definition, constraints, and public examples.

Problem Statement

You are looking to plant a new tree somewhere in your field, which 10 meters wide and 10 meters long. The must be planted at a location that is at least distance away from where any other tree is planted. You are given the location of any other trees in int[]s x and y, where (x[i], y[i]) indicates the location of the i-th tree.

Calculate the total area in which it would be safe to plant the new tree.

Definition

Class:
ThreeTrees
Method:
area
Parameters:
int[], int[], int
Returns:
double
Method signature:
double area(int[] x, int[] y, int distance)
(be sure your method is public)

Notes

  • Your return value must be within 1e-6 absolute or relative error to be considered correct.

Constraints

  • x will have between 0 and 3 elements, inclusive.
  • x and y will have the same number of elements.
  • Each element of x will be between 0 and 10, inclusive.
  • Each element of y will be between 0 and 10, inclusive.
  • distance will be between 0 and 20, inclusive.

Examples

  1. {5}
    {5}
    5
    Returns: 21.460183689207042
    There's a circle of radius 5, centered right in the center of the field, in which we cannot plant the tree. Thus our answer is 100 - pi * 5^2.
  2. {2, 8}
    {2, 8}
    2
    Returns: 74.86725878970901
    Here, there's two circles of radius two that are not available, so we calculate 100 - 2 * pi * 2^2.
  3. {0, 1, 5}
    {0, 0, 3}
    6
    Returns: 17.95288785134835
    Three trees, and whole lot of area that isn't suitable.
  4. {0}
    {0}
    20
    Returns: 0.0
    In a 10x10 field with even a single tree already planted, there's nowhere to put another without being too close to the existing tree.
Back to all problems