UVa 11455 - Behold my quadrangle

11455 - Behold my quadrangle

 * Problem Statement

Summary
Given 4 lengths, you are to determine if these can form a square, rectangle, quadrangle or none of these.

Explanation
Easiest way is to sort the array of lengths then check the following:
 * Square: all 4 sides are equal.
 * Rectangle: each 2 sides are equal.
 * Quadrangle: maximum of these lengths must be less than the sum of other 3.
 * Banana: if none of the above conditions is satisfied, then print "banana".

Gotchas

 * Although the problem statement states all lengths are positive, there are zeros in the input and you will get WA unless you handle these.
 * According to the judge, it is legal to have side of length 0.

Implementations
Notes/Hints on actual implementation here.

Optimizations
Optimizations here.

Input
10 10 8 7 6 9 1 9 1 29 29 29 29 5 12 30 7 0 0 0 0 0 1 0 1 0 0 1 1 1 2 3 6 1 2 3 4 8 8 8 0

Output
quadrangle rectangle square banana square rectangle rectangle banana quadrangle quadrangle

Categories
Computational Geometry