5
\$\begingroup\$

Input: An integer N which represents the polygon's vertices and a list of their x and y coordinates.

Expected output: The smallest difference possible between the area of the(not necessarily convex) polygon and the triangle containing it. The triangle also has to share at least 2 vertices with the polygon. If there is no such triangle print -1.

Example:

4
0,0
2,0
1,1
0,2

Output: 0, because the polygon matches up perfectly with the triangle.

This is so answers will be scored in bytes with less bytes being better.

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to PPCG! As it stands, your question is a little unclear. Could you provide some example inputs and outputs? \$\endgroup\$ – Conor O'Brien Dec 23 '17 at 21:56
  • \$\begingroup\$ Of course, sorry! \$\endgroup\$ – McLinux Dec 23 '17 at 22:00
  • 2
    \$\begingroup\$ If there is no such triangle print -1 the standard on this site is to ignore invalid inputs, letting them lead to undefined beviour or erroring out. \$\endgroup\$ – Uriel Dec 23 '17 at 22:21
  • 1
    \$\begingroup\$ @Uriel Ignoring invalid input isn't a standard iirc, it's just sometimes a recommendation. It is by no means mandatory. \$\endgroup\$ – Conor O'Brien Dec 23 '17 at 22:52
  • 2
    \$\begingroup\$ It isn’t quite clear which way “The triangle also…” is supposed to modify the previous sentence. Do you mean “find the smallest triangle among all triangles that both contain the polygon and share at least 2 vertices with it”? Or do you mean “find the smallest triangle among all triangles that contain the polygon; then, if that triangle doesn’t share 2 vertices with it, print −1”? Please edit the question to clarify this. \$\endgroup\$ – Anders Kaseorg Dec 24 '17 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.