Statistics

Problem Statement for "Truckloads"

Problem Statement

We have a pile of crates at our warehouse that we want to load onto trucks. Our plan is to divide the pile in half forming two smaller piles, then continuing dividing each of the small piles in half until we get piles that will fit on a truck. (Of course, when we divide an odd number of crates in "half", one of the resulting piles will have one more crate than the other.) Our problem is to determine how many trucks we will need to ship the crates.

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.

Definition

Class:
Truckloads
Method:
numTrucks
Parameters:
int, int
Returns:
int
Method signature:
int numTrucks(int numCrates, int loadSize)
(be sure your method is public)

Constraints

  • numCrates will be between 2 and 10,000, inclusive.
  • loadSize loadSize will be be between 1 and (numCrates - 1), inclusive.

Examples

  1. 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.

  2. 15

    1

    Returns: 15

    We will eventually end up with 15 piles, each with just 1 crate.

  3. 1024

    5

    Returns: 256

    1024 divides in half very nicely. We eventually end up with 256 piles, each containing 4 crates.

  4. 10000

    79

    Returns: 128

  5. 894

    22

    Returns: 64

  6. 10000

    1

    Returns: 10000

  7. 15

    5

    Returns: 4

  8. 21

    5

    Returns: 5

  9. 12

    5

    Returns: 4

  10. 11

    5

    Returns: 3

  11. 2

    1

    Returns: 2

  12. 3

    2

    Returns: 2

  13. 10000

    9999

    Returns: 2

  14. 7777

    1

    Returns: 7777

  15. 9999

    1111

    Returns: 16

  16. 8888

    1111

    Returns: 8

  17. 1298

    13

    Returns: 128

  18. 1023

    4

    Returns: 256

  19. 1024

    4

    Returns: 256

  20. 1025

    4

    Returns: 257

  21. 8192

    4

    Returns: 2048

  22. 8191

    4

    Returns: 2048

  23. 8193

    4

    Returns: 2049

  24. 8193

    16

    Returns: 513

  25. 8191

    32

    Returns: 256

  26. 8192

    256

    Returns: 32

  27. 33

    2

    Returns: 17

  28. 5

    2

    Returns: 3

  29. 1024

    5

    Returns: 256

  30. 100

    2

    Returns: 64

  31. 3

    2

    Returns: 2

  32. 10000

    1

    Returns: 10000

  33. 7

    2

    Returns: 4

  34. 17

    3

    Returns: 8

  35. 17

    2

    Returns: 9

  36. 29

    5

    Returns: 8

  37. 14

    3

    Returns: 6

  38. 155

    5

    Returns: 32

  39. 4

    3

    Returns: 2

  40. 9999

    2

    Returns: 5903

  41. 15

    3

    Returns: 7


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: