TopCoder problem "Tetrahedron" used in SRM 355 (Division I Level Two)



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

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 6 6 3",
 "6 0 4 5",
 "6 4 0 4",
 "3 5 4 0"}
Returns: "YES"
4)
    
{"0 6 6 2",
 "6 0 4 5",
 "6 4 0 4",
 "2 5 4 0"}
Returns: "NO"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7539

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10712&pm=7539

Writer:

Petr

Testers:

PabloGilberto , brett1479 , Olexiy , marian

Problem categories:

Geometry, Math