Truckloads
SRM 284 · 2006-01-21 · by dgoodman
Problem Statement
Create a class Truckloads that contains a method numTrucks that is given numCrates (the number of crates at the warehouse) and loadSize (the maximum number of crates that will fit in a truck) and that returns the number of trucks required.
Constraints
- numCrates will be between 2 and 10,000, inclusive.
- loadSize loadSize will be be between 1 and (numCrates - 1), inclusive.
14 3 Returns: 6
After the first division we have two piles each with 7 crates. Each of these piles must be divided giving us 2 piles of 3 and 2 piles of 4. The piles with 4 crates must be further divided giving us 2 piles of 3 and 4 piles of 2. Each of these piles fits into a truck, so we need 6 trucks.
15 1 Returns: 15
We will eventually end up with 15 piles, each with just 1 crate.
1024 5 Returns: 256
1024 divides in half very nicely. We eventually end up with 256 piles, each containing 4 crates.
10000 79 Returns: 128
894 22 Returns: 64
Submissions are judged against all 41 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Truckloads with a public method int numTrucks(int numCrates, int loadSize) · 41 test cases · 2 s / 256 MB per case