TopcoderArchiveVisit Topcoder
SRM20 Jun 2007
SRM 355

Tetrahedron

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given pairwise distances between four hypothetical points. You need to return "YES" if there exist four points in space with such distances between them, and "NO" otherwise (all quotes for clarity only).

The distances are given as a String[] d, each element of which is a single-space separated list of integers. The j-th integer of the i-th element of d gives the distance between the i-th and j-th points.

Definition

Class:
Tetrahedron
Method:
exists
Parameters:
String[]
Returns:
String
Method signature:
String exists(String[] d)
(be sure your method is public)

Constraints

  • d will contain exactly 4 elements.
  • Each element of d will contain exactly 4 integers, separated by single spaces.
  • Each integer in d will be between 0 and 10, inclusive, and contain no extra leading zeroes.
  • The i-th integer of the i-th element of d will be 0.
  • The j-th integer of the i-th element of d will be equal to the i-th integer of the j-th element of d.
  • The j-th integer of the i-th element of d will be between 1 and 10, inclusive, when i is not equal to j.

Examples

  1. {"0 1 1 1",
     "1 0 1 1",
     "1 1 0 1",
     "1 1 1 0"}
    Returns: "YES"
    Just a regular tetrahedron.
  2. {"0 1 2 3",
     "1 0 1 2",
     "2 1 0 1",
     "3 2 1 0"}
    Returns: "YES"
    Four points on a single line.
  3. {"0 1 2 4",
     "1 0 1 2",
     "2 1 0 1",
     "4 2 1 0"}
    Returns: "NO"
    The first and last points are too far away.
  4. {"0 6 6 3",
     "6 0 4 5",
     "6 4 0 4",
     "3 5 4 0"}
    Returns: "YES"
  5. {"0 6 6 2",
     "6 0 4 5",
     "6 4 0 4",
     "2 5 4 0"}
    Returns: "NO"
Back to all problems