Statistics

Problem Statement for "CheckPolygon"

Problem Statement

A simple polygon is a polygon with the following properties:

  • the length of each side is positive
  • no two consecutive sides are parallel
  • no two non-consecutive sides share a common point

You are given two int[]s X and Y, each with N elements. Find out whether there is a simple polygon whose vertices (in the order in which they lie on its boundary) are the points (X[0], Y[0]), (X[1], Y[1]), ... (X[N-1], Y[N-1]).

If the given points are the vertices of a simple polygon, calculate its area A and return a String that contains the decimal representation of A with one digit after the decimal point. If the given points are not the vertices of a simple polygon, return the String "Not simple" (quotes for clarity).

Definition

Class:
CheckPolygon
Method:
check
Parameters:
int[], int[]
Returns:
String
Method signature:
String check(int[] X, int[] Y)
(be sure your method is public)

Notes

  • The correct return value is always uniquely defined by problem statement. In particular, if the points represent a valid polygon, its area is always a rational number with at most one decimal digit.

Constraints

  • X will contain between 3 and 50 elements, inclusive.
  • Each element of X will be between -1,000,000,000 and 1,000,000,000, inclusive.
  • X and Y will contain same number of elements.
  • Each element of Y will be between -1,000,000,000 and 1,000,000,000, inclusive.

Examples

  1. {0,0,1}

    {0,1,0}

    Returns: "0.5"

    These three points are the vertices of a small triangle.

  2. {0,1,2,0,2}

    {0,2,0,1,1}

    Returns: "Not simple"

    These points, in the given order, are not the vertices of a simple polygon. The closed polyline that passes through these five points intersets itself five times.

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

    {0,0,1,2,2,1}

    Returns: "2.0"

    Note that you must return the string "2.0". The printed number must have exactly one decimal place, even if that digit is zero. The string "2" is not a correct answer.

  4. {1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000}

    {1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000,1000000000}

    Returns: "Not simple"

  5. {0,1,1}

    {-1000000000,1000000000,999999999}

    Returns: "0.5"

  6. {-1000000000,0,1000000000}

    {-1000000000,0,1000000000}

    Returns: "Not simple"

  7. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

    {0,20000000,40000000,60000000,80000000,100000000,120000000,140000000,160000000,180000000,200000000,220000000,240000000,260000000,280000000,300000000,320000000,340000000,360000000,380000000,400000000,420000000,440000000,460000000,480000000,500000000,520000000,540000000,560000000,580000000,600000000,620000000,640000000,660000000,680000000,700000000,720000000,740000000,760000000,780000000,800000000,820000000,840000000,860000000,880000000,900000000,920000000,940000000,960000000,980000000}

    Returns: "Not simple"

  8. {-1000000000,-1000000000,-999999999,-999999999,-999999998,-999999998,-999999997,-999999997,-999999996,-999999996,-999999995,-999999995,-999999994,-999999994,-999999993,-999999993,-999999992,-999999992,-999999991,-999999991,-999999990,-999999990}

    {-1000000000,-999999998,-999999998,-999999999,-999999999,-999999998,-999999998,-999999999,-999999999,-999999998,-999999998,-999999999,-999999999,-999999998,-999999998,-999999999,-999999999,-999999998,-999999998,-999999999,-999999999,-1000000000}

    Returns: "15.0"

  9. {-1000000000,-500000000,0,500000000,1000000000}

    {-1000000000,1000000000,-1000000000,1000000000,-1000000000}

    Returns: "Not simple"

  10. {-1000000000,-500000000,0,500000000,1000000000}

    {1000000000,-1000000000,999999999,-1000000000,1000000000}

    Returns: "2000000000500000000.0"

  11. {-1000000000,1000000000,1000000000,-1000000000}

    {1000000000,-1000000000,1000000000,-1000000000}

    Returns: "Not simple"

  12. {-500000000,-500000000,-499999999,-499999999,-500000001,-500000001,-499999998,-499999998,-500000002,-500000002,-499999997,-499999997,-500000003,-500000003,-499999996,-499999996,-500000004,-500000004,-499999995,-499999995,-500000005,-500000005,-499999994,-499999994,-500000006,-500000006,-499999993,-499999993,-500000007,-500000007,-499999992,-499999992,-500000008,-500000008,-499999991,-499999991,-500000009,-500000009,-499999990,-499999990,-500000010}

    {-500000000,-499999999,-499999999,-500000001,-500000001,-499999998,-499999998,-500000002,-500000002,-499999997,-499999997,-500000003,-500000003,-499999996,-499999996,-500000004,-500000004,-499999995,-499999995,-500000005,-500000005,-499999994,-499999994,-500000006,-500000006,-499999993,-499999993,-500000007,-500000007,-499999992,-499999992,-500000008,-500000008,-499999991,-499999991,-500000009,-500000009,-499999990,-499999990,-500000010,-500000010}

    Returns: "Not simple"

  13. {0,52631578,105263156,157894734,210526312,263157890,315789468,368421046,421052624,473684202,526315780,578947358,631578936,684210514,736842092,789473670,842105248,894736826,947368404,999999982,999999982,947368404,894736826,842105248,789473670,736842092,684210514,631578936,578947358,526315780,473684202,421052624,368421046,315789468,263157890,210526312,157894734,105263156,52631578,0}

    {-999999999,1000000000,-999999999,1000000000,-999999999,1000000000,-999999999,1000000000,-999999999,1000000000,-999999999,1000000000,-999999999,1000000000,-999999999,1000000000,-999999999,1000000000,-999999999,1000000000,999999999,-1000000000,999999999,-1000000000,999999999,-1000000000,999999999,-1000000000,999999999,-1000000000,999999999,-1000000000,999999999,-1000000000,999999999,-1000000000,999999999,-1000000000,999999999,-1000000000}

    Returns: "999999982.0"

  14. {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}

    {0,13,25,36,46,55,63,70,76,81,85,88,90,89,87,84,80,75,69,62,54,45,35,24,12,0,-12,-24,-35,-45,-54,-62,-69,-75,-80,-84,-87,-89,-90,-88,-85,-81,-76,-70,-63,-55,-46,-36,-25,-13}

    Returns: "2900.0"

  15. {0, 100000, 100000, 0}

    {0, 0, 100000, 100000}

    Returns: "10000000000.0"

  16. {0, 1, 1, 0, -1, -1}

    {0, 0, 1, 0, 0, -1}

    Returns: "Not simple"

  17. {-999997458,-999997458,-999997460,999997460}

    {-999997458,-999997458,999997460,999997460}

    Returns: "Not simple"

  18. {-999993690,-999993688,-999993688,999993690}

    {-999993690,999993690,999993690,999993690}

    Returns: "Not simple"

  19. {-999995580,-999995580,999995580,999995580}

    {-999995580,999995580,999995578,999995578}

    Returns: "Not simple"

  20. {-999997183,-999997183,-999997183,999997183}

    {-999997183,1,999997183,999997183}

    Returns: "Not simple"

  21. {-999994662,-999994662,0,999994662}

    {-999994662,999994662,999994662,999994662}

    Returns: "Not simple"

  22. {-999988868,-999988868,0,999988868}

    {-999988868,999988868,0,999988868}

    Returns: "Not simple"

  23. {0,0,999997030,1,0,-999997030}

    {0,99,1,0,-1,-1}

    Returns: "49999851501.0"

  24. {0,99,1,0,-1,-1}

    {0,0,999997030,1,0,-999997030}

    Returns: "49999851501.0"

  25. {0,0,999988078,1,0,-999988078}

    {-1,99,1,0,0,-1}

    Returns: "Not simple"

  26. {-1,99,1,0,0,-1}

    {0,0,999988078,1,0,-999988078}

    Returns: "Not simple"

  27. {0,0,999995706,0,-1,-999995706}

    {-1,99,1,0,0,-1}

    Returns: "Not simple"

  28. {-1,99,1,0,0,-1}

    {0,0,999995706,0,-1,-999995706}

    Returns: "Not simple"

  29. {2,6,999996163,4,9,-999996163}

    {3,7,1,5,9,-1}

    Returns: "Not simple"

  30. {3,7,1,5,9,-1}

    {2,6,999996163,4,9,-999996163}

    Returns: "Not simple"

  31. {2,4,999998619,6,9,-999998619}

    {3,5,1,7,9,-1}

    Returns: "3999994466.0"

  32. {3,5,1,7,9,-1}

    {2,4,999998619,6,9,-999998619}

    Returns: "3999994466.0"

  33. {0, 1, 2 }

    {0, 1, 0 }

    Returns: "1.0"


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: