TopCoder problem "Workshop" used in SRM 166 (Division II Level One)



Problem Statement

    

You work in a workshop which makes garden instruments from metal. At the end of each working day there remains a pile of scrap metal that cannot be used to make anything useful. Because you dislike the idea of throwing things away (even scrap metal), you decide to utilize this metal to make some triangular picture frames that can be sold at the local market.

Given a int[] pieces where each element represents the length of a straight metallic piece, return the number of possible different picture frames that can be made from those pieces. Two picture frames are considered to be identical if each of their corresponding sides is equal in length. If no picture frames can be created from pieces then return 0.

 

Definition

    
Class:Workshop
Method:pictureFrames
Parameters:int[]
Returns:int
Method signature:int pictureFrames(int[] pieces)
(be sure your method is public)
    
 

Notes

-A triangle can be formed if, and only if, for every pair of its sides the sum of that pair is longer than the third side.
 

Constraints

-pieces will have between 0 and 50 elements inclusive.
-Each element in pieces will be between 1 and 10000 inclusive.
-pieces will not have any repeated elements.
 

Examples

0)
    
{1,2,3,4,5}
Returns: 3
We can form picture frames with the following sides: {2, 3, 4}, {2, 4, 5} and {3, 4, 5}. So we can form 3 different picture frames.
1)
    
{8,5,3}
Returns: 0
8 + 5 is longer than 3 and 8 + 3 is longer than 5, but 5 + 3 is not longer than 8. Thus we cannot form a single picture frame from these pieces.
2)
    
{4,23,76,22,87,3,1,99}
Returns: 7
3)
    
{10000,9999,9998,9997,9996,1,2,3,4,5}
Returns: 43
4)
    
{100}
Returns: 0
We cannot form any picture frames with just one piece of metal.

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4635&pm=1880

Writer:

dimkadimon

Testers:

lbackstrom , brett1479

Problem categories:

Brute Force, Simple Math