TopcoderArchiveVisit Topcoder
TCO29 Sep 2018
TCO19 SRM 738

FindThePerfectTriangle

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given the ints perimeter and area. Your task is to find a triangle with the following properties:

  • The coordinates of each vertex are integers between 0 and 3000, inclusive.
  • The perimeter of the triangle must be exactly perimeter, and its area must be exactly area.

If there are multiple solutions, you may choose any of them. Return a int[] with six elements: {x1, y1, x2, y2, x3, y3}, where (x1, y1), (x2, y2), and (x3, y3) are the coordinates of the vertices of your triangle. If there is no solution, return an empty int[] instead.

Definition

Class:
FindThePerfectTriangle
Method:
constructTriangle
Parameters:
int, int
Returns:
int[]
Method signature:
int[] constructTriangle(int area, int perimeter)
(be sure your method is public)

Constraints

  • area will be between 1 and 1,000,000, inclusive.
  • perimeter will be between 1 and 1000, inclusive.

Examples

  1. 6
    11
    Returns: { }
    There are no valid triangles with area 6 and perimeter 11.
  2. 6
    12
    Returns: {1, 1, 1, 4, 5, 4 }
    The example output describes a right triangle with vertices at (1, 1), (1, 4) and (5, 4). Its sides have lengths 3, 4, and 5, hence its perimeter is 12. The area of the triangle is (3*4)/2 = 6.
  3. 37128
    882
    Returns: {137, 137, 273, 410, 1, 410 }
  4. 12
    18
    Returns: {1, 1, 4, 5, 1, 9 }
    In this test case our solution constructed an isosceles triangle with vertices at (1, 1), (4, 5) and (1, 9).
  5. 18096
    928
    Returns: {1, 1, 1, 88, 417, 88 }
  6. 1000000
    1000
    Returns: { }
Back to all problems