Connection Status:
Competition Arena > Tetrahedron
SRM 355 · 2007-06-20 · by Petr · Geometry, Math
Class Name: Tetrahedron
Return Type: String
Method Name: exists
Arg Types: (vector<string>)
Problem Statement

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.

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
0)
{"0 1 1 1",
 "1 0 1 1",
 "1 1 0 1",
 "1 1 1 0"}
Returns: "YES"

Just a regular tetrahedron.

1)
{"0 1 2 3",
 "1 0 1 2",
 "2 1 0 1",
 "3 2 1 0"}
Returns: "YES"

Four points on a single line.

2)
{"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.

3)
{"0 2 2 1","2 0 2 2","2 2 0 2","1 2 2 0"}
Returns: "YES"
4)
{"0 2 2 1","2 0 2 1","2 2 0 2","1 1 2 0"}
Returns: "NO"

Submissions are judged against all 129 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Tetrahedron with a public method string exists(vector<string> d) · 129 test cases · 2 s / 256 MB per case

Submitting as anonymous