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
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
{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, 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.
{0, 1, 5}
{0, 0, 3}
6
Returns: 17.95288785134835
Three trees, and whole lot of area that isn't suitable.
{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.
{1, 8, 7}
{1, 9, 2}
4
Returns: 23.73397466186816
{2, 4, 2}
{2, 4, 4}
2
Returns: 72.63914492916592
{2, 4, 2}
{6, 4, 4}
0
Returns: 100.0
{2, 2, 9}
{4, 1, 9}
7
Returns: 2.0716576703716783
{9, 10, 6}
{9, 6, 10}
9
Returns: 6.199327552481009
{4, 5, 6}
{3, 10, 4}
6
Returns: 0.0
{10, 9, 0}
{8, 7, 1}
8
Returns: 1.446784734832363
{1, 10, 6}
{3, 4, 2}
5
Returns: 21.59971975494591
{7, 0}
{6, 6}
13
Returns: 0.0
{8, 8}
{10, 5}
16
Returns: 0.0
{5, 8}
{1, 0}
6
Returns: 36.950808218494785
{10, 0}
{4, 3}
12
Returns: 0.0
{2, 1}
{0, 8}
20
Returns: 0.0
{8}
{5}
20
Returns: 0.0
{9}
{7}
13
Returns: 0.0
{9}
{5}
3
Returns: 79.9758737602333
{8}
{1}
9
Returns: 11.312822756583046
{6}
{0}
3
Returns: 85.86283306769292
{0, 1, 5 }
{0, 0, 3 }
6
Returns: 17.95288785134835
{1, 2, 1 }
{1, 2, 7 }
5
Returns: 37.387073599154974
{3, 4, 5 }
{3, 4, 5 }
3
Returns: 54.91357439296189
{4, 8, 7 }
{4, 1, 9 }
4
Returns: 14.492041513272852
{2, 8 }
{2, 8 }
2
Returns: 74.86725878970901
{2, 3 }
{2, 3 }
3
Returns: 69.48568580609845
{0 }
{0 }
14
Returns: 0.020271432863410155
{2, 3, 4 }
{2, 3, 4 }
2
Returns: 76.36025278755915
{5 }
{5 }
5
Returns: 21.460183689207042
{2, 3 }
{2, 3 }
4
Returns: 56.92738220209412
{2, 3, 4 }
{2, 3, 2 }
4
Returns: 51.900362185963786