TopCoder problem "VolleyballTournament" used in SRM 344 (Division I Level One)



Problem Statement

    

The common method to print the standings for a volleyball tournament is to print the number of won matches, the number of lost matches, the number of won sets, and the number of lost sets for each team.

Each match consists of three to five sets, where each set is won by one of the teams. The first team to win three sets is declared the winner of the match.

You are given one row of the standings table. That is, you are given an int wonMatches, denoting the number of matches won by a team, an int lostMatches, denoting the number of matches lost by that team, an int wonSets, denoting the total number of sets won by that team, and an int lostSets, denoting the total number of sets lost by that team. These numbers represent a possible tournament outcome for a team, and you are to reconstruct the results of all matches for that team, and return them as a comma-separated list, sorted lexicographically. Each match in the list must be formatted as the number of sets won by the team, followed by a dash ('-'), followed by the number of sets lost by the team. The possible outcomes for a match are "0-3", "1-3", "2-3", "3-0", "3-1", and "3-2" (all quotes for clarity only). If multiple different result sets are possible (sets that are reorderings of each other are not considered different), return "AMBIGUITY" (quotes for clarity) instead.

 

Definition

    
Class:VolleyballTournament
Method:reconstructResults
Parameters:int, int, int, int
Returns:String
Method signature:String reconstructResults(int wonMatches, int lostMatches, int wonSets, int lostSets)
(be sure your method is public)
    
 

Notes

-The returned string must not contain spaces.
 

Constraints

-wonMatches and lostMatches will each be between 0 and 100, inclusive.
-At least one of wonMatches and lostMatches will be greater than 0.
-wonSets and lostSets will each be between 0 and 500, inclusive.
-The numbers given will correspond to at least one possible result set.
 

Examples

0)
    
3
3
9
9
Returns: "0-3,0-3,0-3,3-0,3-0,3-0"
1)
    
0
3
6
9
Returns: "2-3,2-3,2-3"
2)
    
3
0
9
3
Returns: "AMBIGUITY"
It could have been "3-0,3-1,3-2" or "3-1,3-1,3-1".
3)
    
1
1
4
4
Returns: "1-3,3-1"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10668&pm=7252

Writer:

Petr

Testers:

PabloGilberto , brett1479 , Yarin , Olexiy

Problem categories:

Simple Math