Statistics

Problem Statement for "Shadow"

Problem Statement

We are going to plant a tree on level ground near a streetlight, and we want to know how big a shadow it will cast. We will model the tree as a (possibly degenerate) rectangular solid, and treat the streetlight as casting rays from a single point. We will use an x,y,z coordinate system that is aligned with the rectangular solid and in which y is the distance above ground level.

int[] tree contains exactly 6 elements, namely the x,y,z coordinates of one corner of the rectangular solid followed by the coordinates of the diagonally opposite corner. int[] light contains exactly 3 elements, the x,y,z coordinates of the streetlight. Given tree and light, return the area of the shadow, or return -1 to indicate that the shadow has an infinite area. If the shadow is an infinitely long line, return 0 as its area.

Definition

Class:
Shadow
Method:
area
Parameters:
int[], int[]
Returns:
double
Method signature:
double area(int[] tree, int[] light)
(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

  • tree will contain exactly 6 elements.
  • light will contain exactly 3 elements.
  • Each element of tree and of light will be between 1 and 10, inclusive.
  • The coordinates of the light will not lie on the boundary of the tree.

Examples

  1. {1,1,1, 10,1,1}

    {5,5,5}

    Returns: 0.0

    This tree is just a line so its shadow has no area.

  2. {1,3,1, 10,1,1}

    {2,2,2}

    Returns: -1.0

    This tree is just a rectangle. Its shadow covers an infinite rectangular area on the ground.

  3. {1,1,1, 2,2,2}

    {3,3,3}

    Returns: 15.75

    This is a unit cube one unit above the ground. The shadowed area is a six-sided polygon.

  4. {1,1,1, 3,3,3}

    {2,2,2}

    Returns: -1.0

    When the light is inside the tree the shadow extends everywhere.

  5. {1,1,1, 3,3,3}

    {2,5,2}

    Returns: 25.0

  6. {1,1,1, 3,1,3}

    {2,2,2}

    Returns: 16.0

  7. {8,1,1,8,3,3}

    {10,5,2}

    Returns: 9.375

  8. {1,1,2, 2,2,2}

    {3,3,3}

    Returns: 3.375

  9. {2,1,1, 2,2,2}

    {3,3,3}

    Returns: 3.375

  10. {1,1,2, 2,2,2}

    {3,3,3}

    Returns: 3.375

    111 222 333 top: 121 222 333 = 9 rhs: 211 222 333 = 3.375 z=2: 112 222 333 = 3.375 total = 15.75

  11. {4, 7, 3, 7, 5, 9}

    {2, 8, 8}

    Returns: 1493.3333333333335

  12. {5, 3, 2, 2, 1, 10}

    {6, 6, 10}

    Returns: 106.24000000000001

  13. {4, 10, 5, 9, 10, 6}

    {9, 2, 1}

    Returns: 0.0

  14. {3, 10, 6, 7, 9, 2}

    {10, 7, 10}

    Returns: 0.0

  15. {9, 1, 6, 8, 3, 7}

    {9, 6, 4}

    Returns: 6.5600000000000005

  16. {2, 1, 3, 10, 9, 5}

    {1, 7, 2}

    Returns: -1.0

  17. {5, 3, 6, 5, 9, 7}

    {5, 5, 8}

    Returns: 0.0

  18. {8, 9, 2, 10, 4, 4}

    {6, 9, 5}

    Returns: -1.0

  19. {1, 9, 1, 3, 10, 3}

    {3, 7, 3}

    Returns: 0.0

  20. {3, 2, 4, 4, 1, 9}

    {7, 1, 4}

    Returns: 0.0

  21. {8, 8, 7, 5, 10, 8}

    {10, 9, 1}

    Returns: -1.0

  22. {4, 3, 9, 10, 10, 8}

    {2, 2, 10}

    Returns: 0.0

  23. {1, 3, 4, 10, 9, 4}

    {10, 6, 3}

    Returns: -1.0

  24. {3, 3, 3, 2, 7, 2}

    {7, 2, 4}

    Returns: 0.0

  25. {8, 3, 7, 6, 2, 5}

    {4, 4, 7}

    Returns: 88.0

  26. {9, 8, 1, 2, 4, 5}

    {7, 5, 7}

    Returns: -1.0

  27. {3, 8, 5, 3, 7, 9}

    {1, 3, 3}

    Returns: 0.0

  28. {7, 9, 8, 6, 1, 8}

    {6, 2, 1}

    Returns: -1.0

  29. {1, 7, 5, 4, 6, 7}

    {10, 3, 8}

    Returns: 0.0

  30. {7, 6, 7, 3, 6, 4}

    {10, 4, 6}

    Returns: 0.0

  31. {6, 4, 8, 7, 7, 2}

    {9, 10, 9}

    Returns: 120.83333333333334

  32. {1, 2, 9, 10, 10, 8}

    {7, 8, 6}

    Returns: -1.0

  33. {8, 10, 8, 6, 4, 1}

    {10, 8, 7}

    Returns: -1.0

  34. {6, 8, 9, 10, 2, 5}

    {5, 2, 9}

    Returns: 0.0

  35. {7, 6, 9, 6, 5, 2}

    {9, 3, 1}

    Returns: 0.0

  36. {1, 7, 5, 5, 1, 2}

    {2, 5, 10}

    Returns: -1.0

  37. {9, 10, 9, 8, 1, 2}

    {3, 2, 7}

    Returns: -1.0

  38. {6, 1, 8, 10, 1, 5}

    {9, 7, 10}

    Returns: 16.333333333333336

  39. {4, 6, 6, 7, 4, 2}

    {10, 3, 2}

    Returns: 0.0

  40. {1, 2, 1, 7, 3, 5}

    {9, 7, 2}

    Returns: 77.91

  41. {8, 10, 2, 7, 5, 8}

    {6, 5, 2}

    Returns: 0.0

  42. {1, 9, 5, 4, 1, 10}

    {2, 5, 6}

    Returns: -1.0

  43. {6, 6, 7, 3, 7, 5}

    {8, 3, 4}

    Returns: 0.0

  44. {1, 1, 1, 5, 10, 1 }

    {8, 2, 1 }

    Returns: 0.0

  45. {5, 1, 7, 5, 9, 8 }

    {5, 5, 5 }

    Returns: 0.0

  46. {3, 5, 3, 5, 7, 3 }

    {1, 6, 3 }

    Returns: 0.0

  47. {1, 3, 1, 10, 4, 5 }

    {5, 2, 5 }

    Returns: 0.0

  48. {5, 5, 5, 5, 7, 5 }

    {6, 6, 6 }

    Returns: 0.0

  49. {5, 5, 5, 6, 5, 6 }

    {3, 3, 3 }

    Returns: 0.0

  50. {1, 1, 1, 1, 5, 5 }

    {1, 3, 6 }

    Returns: 0.0

  51. {2, 2, 2, 3, 3, 3 }

    {1, 1, 1 }

    Returns: 0.0

  52. {1, 1, 1, 3, 3, 1 }

    {4, 2, 1 }

    Returns: 0.0

  53. {1, 1, 1, 1, 10, 1 }

    {2, 2, 2 }

    Returns: 0.0

  54. {2, 2, 2, 2, 4, 2 }

    {1, 3, 2 }

    Returns: 0.0

  55. {1, 1, 1, 1, 1, 3 }

    {1, 1, 10 }

    Returns: 0.0

  56. {5, 1, 5, 6, 2, 6 }

    {2, 1, 2 }

    Returns: 0.0

  57. {1, 1, 1, 2, 2, 2 }

    {3, 3, 5 }

    Returns: 22.5


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: