Statistics

Problem Statement for "SolidArea"

Problem Statement

A polygon is a closed plane figure with n>2 sides. In this problem, a polygon will be given as int[]s xs and ys. The kth point of the polygon will have, as x and y coordinates, the kth elements of xs and ys respectively. There will be an edge between every two consecutive points given. In addition, there will be an edge between the first and last points given.

A dilation is a transformation in plane geometry that takes every point of a figure, and multiplies its x and y coordinates by a given factor. A dilation by a factor greater than 1 acts to "blow-up" a figure, increasing its size proportionally.

An orthogonal shift is a transformation applied to a plane figure that moves it along a line that is perpendicular to its face. Consider a figure drawn in the x-y plane. An orthogonal shift would change this figure's z-coordinate by the given shift amount.

In this problem we are going to form a 3-dimensional solid object using a polygon, a dilation, and an orthogonal shift. The base of the solid will be the polygon given by xs and ys. The top face will be a dilated copy of the base that has been shifted in a direction orthogonal to the plane of the base. In other words, the bottom and top of the solid will be parallel polygons separated by an integral amount. The top face will be a proportionate copy of the bottom face. To complete the solid, edges will be drawn from every vertex in the base to its corresponding vertex in the dilated top face. For example:
xs = {0,1,1,0}
ys = {0,0,1,1}
factor = 3
shift = 5
The base of the figure corresponding to the input shown above will be a square including the points (0,0),(1,0),(1,1),(0,1). Dilating this square by a factor of three will produce the polygon with points (0,0),(3,0),(3,3),(0,3). Note, to produce this dilation we multiplied every coordinate by the given factor. This larger square will be shifted 5 units in the z-direction (orthogonal to the base). The resultant figure is finished by drawing edges between each point and its corresponding point in the shifted and dilated copy. If thought about in 3-dimensions, the base would have points each having a z-coordinate of 0, whereas the top would have points each having a z-coordinate of 5. The edges would connect (0,0,0) to (0,0,5), (1,0,0) to (3,0,5), (1,1,0) to (3,3,5), and (0,1,0) to (0,3,5). Had factor been 1, the resulting object would instead have been a rectangular solid.

Your method will return the surface area of the resulting solid rounded down. The surface area is calculated by adding together the areas of the base, the top, and the faces generated by the edges connecting the base and top.

Definition

Class:
SolidArea
Method:
totalArea
Parameters:
int[], int[], int, int
Returns:
int
Method signature:
int totalArea(int[] xs, int[] ys, int factor, int shift)
(be sure your method is public)

Constraints

  • xs will contain between 3 and 50 elements inclusive
  • xs and ys will contain the same number of elements
  • factor will be between 1 and 50 inclusive
  • shift will be between 1 and 50 inclusive
  • Each element of xs will be between -100 and 100 inclusive
  • Each element of ys will be between -100 and 100 inclusive
  • There will be no repeated points
  • No two non-consecutive edges in the resulting polygon may intersect with each other
  • No two consecutive edges in the resulting polygon may have the same slope
  • The resulting surface area prior to rounding will not be within .001 of an integer

Examples

  1. {0,1,1,0}

    {0,0,1,1}

    3

    5

    Returns: 51

    The example from above. Given areas are approximates rounded for brevity: Base area = 1.0 Top area = 9.0 Face areas = 10.0, 10.7703, 10.7703, 10.0

  2. {-1,1,1,-1}

    {-1,-1,1,1}

    2

    1

    Returns: 36

    The base is a square centered at the origin. The top has been dilated by a factor of 2 and shifted 1 unit. Given areas are approximates rounded for brevity: Base area = 4.0 Top area = 16.0 Face areas = 4.243, 4.243, 4.243, 4.243

  3. {0,2,6,6,8,8,6,2,2,0}

    {10,10,6,10,10,0,0,4,0,0}

    9

    9

    Returns: 14993

    This base is a polygon resembling the letter N. The top has been dilated by a factor of 9 and shifted 9 units. Given areas are approximates rounded for brevity: Base area = 64.0 Top area = 5184.0 Face areas = 805.047, 1936.801, 976.729, 805.047, 3231.486, 90.0, 993.177, 367.151, 90.0, 450.0

  4. {-100,100,100,-100}

    {-100,-100,100,100}

    50

    50

    Returns: 200005203

  5. {0,1,3,1,3,0,-3,-1,-3,-1}

    {3,1,1,-1,-3,-2,-3,-1,1,1}

    10

    9

    Returns: 3601

  6. {0,10,10,0,5}

    {0,0,10,10,5}

    1

    1

    Returns: 194

  7. {0,20,15,20,0,5}

    {0,0,10,20,20,10}

    1

    1

    Returns: 684

  8. {0,2,6,6,8,8}

    {10,10,6,10,10,0}

    1

    1

    Returns: 100

  9. {99,-99,100,100}

    {100,-99,0,100}

    1

    1

    Returns: 20702

  10. {-38,-22,43,90,85,72,-46,43,-80,-89,7,7,17,83,-65}

    {-26,-3,-5,-72,-81,-64,-55,-83,-76,64,23,80,95,-7,39}

    48

    37

    Returns: 101760174

  11. {-18,-81,-32,25,9,-84,-66,54,24,95,85,85,-84,-29,22}

    {-43,-3,-51,-32,-50,-61,-62,-72,-66,-57,56,-23,95,6,17}

    21

    12

    Returns: 17215461

  12. {62,-61,45,-12,-62,-91,-84,-92,-1,18,42,18,-13,64,-76}

    {-51,-37,-75,-64,-67,-85,-78,-13,78,51,7,16,0,-9,-4}

    41

    48

    Returns: 51991404

  13. {84,-52,-31,1,-7,-61,-97,-58,16,13,9,6,85,24,47}

    {73,60,35,-3,-38,42,-50,-46,-90,-26,-19,-1,-63,-1,-13}

    30

    30

    Returns: 27378166

  14. {-88,-45,-69,-99,-88,-64,34,-35,81,-18,63,75,62,42,-2}

    {-87,52,1,-84,-44,78,99,-28,95,-62,13,-58,-77,-36,-100}

    1

    22

    Returns: 70049

  15. {-33,9,-51,37,51,94,33,62,3,4,-9,-26,-46,-72,-76}

    {-10,38,85,66,90,16,-46,51,-6,-81,-35,-49,-57,-98,-87}

    38

    17

    Returns: 38056872

  16. {-32,-62,-72,-87,-73,-77,-91,20,97,90,19,28,70,21,71}

    {-61,-85,-61,-37,-66,-94,-27,83,68,-22,47,-17,-20,-60,-73}

    18

    17

    Returns: 15074877

  17. {-93,-40,-59,-100,-99,-18,14,-47,-21,71,91,98,62,90,47}

    {81,19,-1,-29,-30,-6,-61,56,30,-25,-82,-27,30,-15,33}

    19

    40

    Returns: 9545386

  18. {60,17,-9,12,-97,-87,-50,-78,-36,47,-32,87,93,83,18}

    {-47,-57,-54,-87,-85,36,-11,36,64,40,4,5,-88,-52,-72}

    27

    5

    Returns: 35614212

  19. {-94,-1,-40,16,-20,90,16,5,75,40,79,20,50,-6,-60}

    {42,30,71,68,-45,-99,-10,22,-59,28,52,40,50,94,64}

    3

    5

    Returns: 254219

  20. {-90,18,-48,71,80,92,83,67,-75,23,-58,-6,-31,-16,-86}

    {80,33,93,46,34,65,27,-90,-51,-38,32,-27,-23,-29,-7}

    46

    45

    Returns: 103483357

  21. {95,45,-63,-94,-76,-31,-45,-52,41,52,65,48,97,89,53,47,-69,-30,45,-16,68,78,28,25,90,59,74,-86,-75,-95,-75,-99,64,9}

    {-45,49,-44,-9,10,24,70,74,46,75,47,59,10,53,82,71,76,89,97,84,85,95,86,92,97,95,99,95,90,-10,-53,-56,-88,-39}

    43

    10

    Returns: 156983812

  22. {-2,-30,-49,-27,28,39,-58,-84,-24,-98,-66,-54,-83,-71,-60,-59,-33,-35,-69,-23,-69,11,14,18,20,22,30,30,33,12,-9,-17,-32,-18,-26,-3,6,6,-34,-22,-34}

    {-69,-51,-44,-99,-62,3,60,94,-16,55,-23,-72,-37,-76,-67,-76,-92,-82,3,-49,9,-58,-35,13,-24,-43,-1,-26,-29,-61,-80,-77,-57,-60,-59,-74,-62,-57,-26,-50,-40}

    32

    36

    Returns: 51267872

  23. {36,-33,-71,-99,-80,-65,-76,-83,-80,-88,-79,-51,-72,-70,-37,-31,84,20,3,72,86,79,93,55,35,23,72,81,-1,-29,-15,-3,0}

    {-55,-85,-24,-35,-93,-66,-63,-55,-42,-41,-34,-60,-30,-31,-81,-98,-76,49,89,-20,-54,4,93,72,44,74,88,96,89,65,-52,-34,47}

    23

    6

    Returns: 32001183

  24. {-91,-10,-38,-89,-32,-58,-96,-99,-87,-69,-60,-62,-47,-93,-100,-72,-1,39,47,-32,41,0,-26,-47,-27,-57,-27,-26,-68,-53,-10,-36,-86}

    {-66,97,86,5,86,14,-8,-32,-16,-13,3,1,26,-56,-64,-83,-86,-96,96,24,-15,-85,-53,-64,-32,-58,-29,10,-36,-71,-79,-78,-66}

    14

    20

    Returns: 11396583

  25. {-84,-64,38,-26,82,7,-85,19,40,-100,-94,-54,-1,-26,-13,-61,-11,-68,-23,6,4,20,2,-71,-41,-60}

    {5,97,41,-29,16,-18,-55,-36,-40,-73,-1,-8,50,14,27,-35,29,-44,6,35,51,47,53,17,83,55}

    44

    12

    Returns: 87163268

  26. {55,59,-53,-80,-44,-71,36,-56,-30,-23,-46,-32,57,16,13,-14,-5,-29,-35,-42,-48,-86,-95,-69,-92,-91,-80,-52,54,52,37,23,49,22}

    {-64,71,-98,-7,81,90,58,-53,-37,-35,-54,-60,69,93,93,81,73,85,80,98,84,97,97,42,-36,-82,-76,-100,27,-8,-16,-18,-18,-58}

    29

    30

    Returns: 43304495

  27. {-41,-17,-91,-75,90,13,51,43,9,-22,-10,-22,-53,-18,-67,-72,-42,-78,-99,-47,-64,-100,-87,-76,-78,-88,-96,-84,-58,-73,-79,-89,-72,-79,-86,-82,-84,-84,-89,-75,-85,-91,-59,-72,-42,-37}

    {-8,-22,95,94,95,32,71,82,78,-92,-22,-33,-45,-24,8,-29,-95,-95,14,-92,-49,21,20,-2,43,35,57,78,25,38,49,62,49,61,69,67,69,74,68,53,61,65,14,8,15,-6}

    3

    3

    Returns: 502046

  28. {67,-54,-91,97,53,-10,-5,-84,14,-68,-51,-75,-8,-99,-37,-99,-93,-90,-94,-100,-94,52,53,20,-27}

    {-38,47,87,39,-77,-74,-53,-21,-100,-67,-79,-71,-98,-84,-87,-72,-38,55,48,30,77,-40,-35,-12,24}

    26

    35

    Returns: 49516892

  29. {-96,-66,10,-81,-59,-52,-66,-70,-97,-95,-9,92,-13,-59,-25,24,-13,28,12,43,21,30,-90,-57,-75}

    {18,75,-99,-18,-51,-86,-63,-46,-20,91,87,75,52,77,65,71,79,72,58,74,83,76,90,79,82}

    26

    6

    Returns: 41040104

  30. {8,72,57,46,-17,2,-10,-50,-58,-21,-90,-87,-47,-75,-33,-35,-54,-41,-68,-63,-49,-76,-79,-29,41}

    {-51,48,-9,-71,-90,22,78,52,61,-59,-28,89,9,-20,-27,-22,-16,-3,85,56,20,81,94,86,80}

    11

    35

    Returns: 5893435

  31. {31,-91,-79,96,-88,6,37,50,91,3,-59,-28,1,4,7,22,-21,8,51,41,19,13,50,26,52,73,52,54,25}

    {-38,-54,-70,-65,-57,-44,-53,9,50,91,-35,13,52,3,88,9,-23,-15,30,29,49,85,63,56,55,45,43,35,-20}

    37

    14

    Returns: 60240475

  32. {37,10,8,-19,17,59,-62,37,-5,51,41,-58,-21,-53,-13,-89,-69,-34,-23,-40,-30,-15,-3,-37,-63,-99,-95,-96,-91,-84,-92,-75,-82,23,-42,7,-37,-65,-2,4,-17,57}

    {-77,6,-76,5,24,53,70,50,60,53,53,-23,47,55,53,60,-73,-42,-30,-37,-14,-32,-61,-64,-81,-39,-45,-85,-83,-77,-79,-73,-92,-80,-81,-80,-78,-85,-66,-76,-73,-84}

    18

    14

    Returns: 19627899

  33. {1,-84,-7,66,70,-1,31,59,60,59,39,76,74,-40,47,92,88,97,99,84,97,77,97,82,86,56,55,85,94,-78,23,-86,-68,-54,-39}

    {-6,47,26,5,-51,0,-25,-93,-80,-85,-36,-54,45,43,93,37,91,71,29,5,-32,-47,-67,-56,-84,-59,-72,-88,-93,-100,-25,-78,-14,-6,-30}

    9

    19

    Returns: 5259904

  34. {-79,-35,80,65,68,-2,30,32,63,40,33,47,-34,-61,-45,89,76,69,69,83,-79,-93,78,-76,-99,-78}

    {-89,9,82,72,-32,-80,21,-44,4,-1,-24,40,-47,-100,-91,-94,25,-2,69,85,62,18,84,14,-37,-97}

    9

    35

    Returns: 5744461

  35. {8,-76,-1,34,42,-8,19,74,49,-5,-71,4,-92,-39,-83,-98,-96,-40,-93,-83,-48,-53,-89,-61,-84,-54,-76,-90,-87}

    {-96,-89,-69,-31,-85,-76,-82,-91,84,-59,-20,8,80,-7,45,80,-6,-40,-48,-47,-59,-79,-65,-72,-59,-73,-61,-57,-91}

    40

    49

    Returns: 100365298

  36. {-100,29,-40,-12,-32,45,-56,18,54,-5,73,-6,64,-29,-5,-9,-46,-66,-84,-56,-15,-7,-21,-36,-59,-61,-55,-58,-52,-57,-54,-48,-51,-53,-54,-53,-69,-74,-67,-88,-80,-82,-86,-84}

    {92,95,28,21,-1,59,-92,-19,-48,-57,-85,-61,-84,-89,-84,-66,-96,-89,44,29,70,94,67,93,52,83,91,66,68,65,63,76,92,80,72,93,80,57,92,62,-18,-34,30,-84}

    45

    6

    Returns: 166037855

  37. {71,-21,52,95,-5,0,-89,-93,4,-66,-79,-31,-14,-61,-9,-32,-19,-18,12,-65,-39,-22,-64,-46,-37,-65,-69,50,92,99,82,74,53,90,55,-7,47,-12,-25,25,53,85}

    {-1,5,-79,31,46,76,38,-22,-96,-41,-25,45,69,1,56,17,-27,-4,-45,-36,9,42,-34,2,26,-28,-36,-98,-50,-48,-22,-27,-77,-38,-91,-14,-93,-10,4,39,27,15}

    45

    24

    Returns: 151217287

  38. {-50,64,-3,12,-17,-1,-6,-51,-59,-40,-1,31,-13,-54,-55,-35,35,-9,-38,-8,-2,-29,-20,-19,-27,-38,-48,-36,-31}

    {-37,-60,79,34,59,48,82,-3,-63,-61,-78,-54,-69,-47,-34,-8,-33,-45,-35,-32,-24,-11,-24,-32,-31,-28,-33,-29,-31}

    21

    38

    Returns: 12861242

  39. {68,45,70,65,82,74,14,-90,-72,-53,-36,-43,39,-7,83,88,94,91,91,86,3,27,-14,-95,30,-25,35,18,42}

    {-26,45,-7,50,50,-33,-31,63,-100,-93,-43,-18,-58,-97,-95,-14,-97,-50,-51,95,25,51,55,70,-7,28,-7,-11,-8}

    23

    50

    Returns: 36348486

  40. {-100,-27,-76,-95,53,69,8,4,-13,-19,-79,-24,-20,-20,-36,-90,-80,-28,34,94,96,-59,-47,-51,-55,-60,-58,-73,-67,-61,-78,-59,-54,-45,52,69,-10,-27}

    {70,96,-15,-97,-27,-90,-70,-74,-88,-62,-93,-77,-71,-92,-85,-96,-97,-92,-94,-91,20,-78,46,19,12,-5,-67,-82,-35,-18,-51,13,21,54,57,83,71,99}

    10

    40

    Returns: 7662852

  41. {12,43,52,58,88,58,69,48,55,65,55,54,51,47,52,47,59,-7,2,7,-4,-84,-29,-40,-97,50,43,23}

    {-73,92,-64,9,-5,63,5,44,28,12,17,-31,-8,44,-12,49,90,99,29,88,-61,31,-74,-80,-95,-75,24,-29}

    17

    6

    Returns: 16083351

  42. {-25,-82,82,36,89,53,-57,-51,-69,-98,-77,-64,-78,-64,-68,-66,-62,-58,-59,-54,-61,-57,-52,-51,-42,-46,-51,-49,-48,-44}

    {82,-81,-35,37,-23,82,83,21,99,-55,-16,75,-31,-26,-12,55,50,4,24,31,57,44,25,17,64,54,43,53,74,73}

    4

    38

    Returns: 1114942

  43. {-89,22,-83,81,55,43,46,88,85,68,70,78,89,98,86,17,-37,17,-18,-100,2,-7,-19,39,25,67,59,51,41,41,32,33,18,-9,-95,-34,-55,-87,-96,-41,-47,-61,-88,-52,-39}

    {-32,15,29,28,-62,-3,-70,-94,-16,-59,-13,-18,7,-92,62,60,51,85,89,60,38,49,53,57,30,53,47,29,31,38,31,30,29,32,47,30,32,29,25,23,2,12,-31,4,-6}

    25

    50

    Returns: 39563944

  44. {-31,92,80,-69,11,-21,-77,-17,95,36,76,95,91,-13,60,8,13,30,-22,14,7,23,11,7,-6}

    {-2,-36,-49,-43,57,29,14,97,99,17,22,-8,-18,-2,19,11,41,78,85,64,76,63,48,23,16}

    19

    14

    Returns: 14765866

  45. {1,15,-16,-78,42,34,45,55,41,54,64,69,47,92,57,23,25,6,26,-50,-39,-58,-72,1,-3,-72,-76,-59,-63,2}

    {-89,61,43,88,91,15,28,32,72,66,70,95,-54,-64,-92,-56,-84,-58,-95,-78,-93,-95,-90,-50,-26,-43,55,16,52,39}

    39

    39

    Returns: 83102064

  46. {51,-45,94,54,-3,-85,16,82,70,2,18,-6,14,-20,-23,-16,-65,53,-16,7,22,32,-45,-32,-15,-9,-90,-87,-88,-90,-68,-71,-49,-53,-39}

    {99,42,90,-10,-8,-86,-33,-11,-18,-95,-72,-87,-75,-100,-88,-87,-82,-37,-60,-46,-38,-32,-69,-61,-52,-47,-96,-55,55,74,-3,24,-13,27,55}

    16

    13

    Returns: 17771204

  47. {-55,58,72,33,25,-56,-16,-54,-70,-73,23,0,-45,-39,-74,-70,-83,-86,-98,-95,-45,-11,41,99,80,88,94,-33,-58,16,50,73}

    {45,76,0,13,-21,-35,-58,-51,2,29,52,54,45,44,40,-26,38,83,-1,0,-88,-85,-15,7,53,64,93,88,62,80,82,85}

    45

    32

    Returns: 138158445

  48. {-56,47,-73,81,-97,-48,-77,-53,-10,-57,-95,40,-14,-73,62,2,13,6,-24,-39,8,-75,-54,-33,-45,-12,-13,-4,4}

    {49,93,-4,-9,-29,38,69,69,71,81,90,99,94,87,98,87,81,77,83,82,91,86,87,78,80,72,80,77,77}

    35

    42

    Returns: 71614575

  49. {-16,-53,4,48,8,-55,49,36,86,42,82,98,23,-19,-98,-27,-43,-59,-53,-67,-55,-76,-84,-99,-55,6,-14,-5,-15,-14,-30,-21,-16,-18,-59}

    {40,77,-69,4,59,94,43,31,44,-35,-14,-20,-97,-38,69,-10,40,71,40,53,23,51,60,90,92,57,26,35,-6,66,62,60,63,45,89}

    4

    23

    Returns: 730255

  50. {-90,66,74,81,13,64,0,-2,24,-46,49,56,-73,-58,-32,21,-14,9,19,21,25,56,38,37,12,-11,-3,16,-18,-6,24,77,94,79,89,90,10,-75}

    {-36,70,-62,78,98,73,91,48,52,8,61,64,-11,61,99,92,94,91,86,91,85,76,82,85,96,97,96,93,98,97,99,82,96,-49,28,-92,-30,-96}

    24

    18

    Returns: 51863097

  51. { 0, 10, 30, 10, 30, 0, -30, -10, -30, -10 }

    { 30, 10, 10, -10, -30, -20, -30, -10, 10, 10 }

    50

    49

    Returns: 7579831

  52. { 0, 1, 1, 0 }

    { 0, 0, 1, 1 }

    3

    5

    Returns: 51

  53. { 0, 2, 6, 6, 8, 8, 6, 2, 2, 0 }

    { 10, 10, 6, 10, 10, 0, 0, 4, 0, 0 }

    9

    9

    Returns: 14993


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: