Statistics

Problem Statement for "FindPolygons"

Problem Statement

Alice is a high school student. One day, her teacher asked her to draw a simple polygon (see Notes for a definition). The polygon must satisfy two conditions:

First, each of its vertices must be at a grid point. (I.e., both coordinates of each vertex must be integers.)

Second, the perimeter of the polygon must be exactly equal to the integer L.

You are given the int L. If there is no such polygon, return -1. If there is at least one such polygon, find the one which has the least number of sides. If there are still more than one choice, find the one with the smallest possible difference between the lengths of its longest side and its shortest side. Return the difference between the lengths of its longest side and its shortest side.

Definition

Class:
FindPolygons
Method:
minimumPolygon
Parameters:
int
Returns:
double
Method signature:
double minimumPolygon(int L)
(be sure your method is public)

Notes

  • A simple polygon is a polygon such that no two consecutive sides are parallel and no two non-consecutive sides share a common point.
  • Return values with absolute or relative error at most 1e-9 will be accepted as correct.

Constraints

  • L will be between 1 and 5000, inclusive.

Examples

  1. 1

    Returns: -1.0

  2. 2

    Returns: -1.0

  3. 3

    Returns: -1.0

  4. 4

    Returns: 0.0

    There is no triangle whose perimeter is 4, but there is a square.

  5. 5

    Returns: -1.0

    There is no simple polygon that matches all the constraints.

  6. 6

    Returns: 1.0

  7. 12

    Returns: 2.0

    There is a triangle whose sides are 3, 4, 5.

  8. 14

    Returns: 1.0

  9. 16

    Returns: 1.0

  10. 18

    Returns: 3.0

  11. 20

    Returns: 0.0

  12. 60

    Returns: 10.0

  13. 62

    Returns: 1.0

  14. 64

    Returns: 4.0

  15. 66

    Returns: 19.0

  16. 68

    Returns: 9.0

  17. 70

    Returns: 9.0

  18. 72

    Returns: 6.0

  19. 74

    Returns: 1.0

  20. 76

    Returns: 18.0

  21. 78

    Returns: 22.0

  22. 80

    Returns: 5.0

  23. 82

    Returns: 1.0

  24. 84

    Returns: 4.0

  25. 86

    Returns: 1.0

  26. 88

    Returns: 18.0

  27. 90

    Returns: 11.0

  28. 92

    Returns: 0.0

  29. 94

    Returns: 1.0

  30. 96

    Returns: 6.0

  31. 98

    Returns: 11.0

  32. 100

    Returns: 2.0

  33. 102

    Returns: 1.0

  34. 104

    Returns: 15.0

  35. 106

    Returns: 1.0

  36. 108

    Returns: 9.0

  37. 110

    Returns: 27.0

  38. 112

    Returns: 7.0

  39. 114

    Returns: 26.0

  40. 116

    Returns: 0.0

  41. 118

    Returns: 1.0

  42. 120

    Returns: 20.0

  43. 122

    Returns: 1.0

  44. 124

    Returns: 0.0

  45. 126

    Returns: 6.0

  46. 128

    Returns: 8.0

  47. 130

    Returns: 11.0

  48. 132

    Returns: 22.0

  49. 134

    Returns: 1.0

  50. 136

    Returns: 18.0

  51. 138

    Returns: 1.0

  52. 140

    Returns: 18.0

  53. 142

    Returns: 1.0

  54. 144

    Returns: 9.0

  55. 146

    Returns: 1.0

  56. 148

    Returns: 0.0

  57. 4999

    Returns: -1.0

  58. 4953

    Returns: -1.0

  59. 99

    Returns: -1.0

  60. 3001

    Returns: -1.0

  61. 4948

    Returns: 0.0

  62. 4954

    Returns: 1.0

  63. 4962

    Returns: 1627.0

  64. 5000

    Returns: 74.0

  65. 4984

    Returns: 819.0

  66. 4894

    Returns: 1.0

  67. 2910

    Returns: 10.0

  68. 3918

    Returns: 1231.0

  69. 196

    Returns: 1.0

  70. 156

    Returns: 2.0

  71. 150

    Returns: 3.0

  72. 154

    Returns: 31.0

  73. 1164

    Returns: 4.0

  74. 4356

    Returns: 6.0

  75. 722

    Returns: 1.0

  76. 4906

    Returns: 929.0

  77. 36

    Returns: 3.0

  78. 4780

    Returns: 1463.0

  79. 4964

    Returns: 657.0

  80. 40

    Returns: 9.0

  81. 15

    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: