VolleyballTournament
SRM 344 · 2007-03-28 · by Petr
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.
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.
3 3 9 9 Returns: "0-3,0-3,0-3,3-0,3-0,3-0"
0 3 6 9 Returns: "2-3,2-3,2-3"
3 0 9 3 Returns: "AMBIGUITY"
It could have been "3-0,3-1,3-2" or "3-1,3-1,3-1".
1 1 4 4 Returns: "1-3,3-1"
1 0 3 0 Returns: "3-0"
Submissions are judged against all 168 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class VolleyballTournament with a public method string reconstructResults(int wonMatches, int lostMatches, int wonSets, int lostSets) · 168 test cases · 2 s / 256 MB per case