Equity
TCO '03 Semifinals 3 · 2003-10-07 · by dgoodman
Problem Statement
Among solutions that have minimum inequity, we want to choose the one that has the fewest pieces. Each whole bar counts as one piece, while each split bar counts as either two or three pieces depending on how it was split. Create a class Equity that contains a method minPieces that takes n, the number of people, and k, the number of candy bars, and returns the smallest number of pieces that we will need in order to divide the candy bars with minimum inequity.
Constraints
- n will be between 1 and 1000 inclusive
- k will be between 1 and 1000 inclusive
12 11 Returns: 18
Split 2 of the bars into thirds, and 3 of the bars into halves. Give 6 of the people a third of a bar and a half of a bar each. Give the other 6 people a whole bar each. This results in an inequity of 1 - (1/2+1/3) = 1/6 which is the minimum possible inequity. There are 18 pieces: 6 thirds, 6 halves, and 6 wholes.
12 4 Returns: 12
Give each person a third of a bar.
12 1 Returns: 3
The best we can do is to give 3 people a third, and the other 9 nothing.
12 1000 Returns: 1008
13 1000 Returns: 1007
Submissions are judged against all 61 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Equity with a public method int minPieces(int n, int k) · 61 test cases · 2 s / 256 MB per case