Statistics

Problem Statement for "BoardSplitting"

Problem Statement

A construction company recently ordered some boards of length desiredLength from a lumber company. By mistake, the lumber company instead delivered boards of length actualLength. The construction company doesn't have time to reissue the order, so instead they will cut and glue together the boards they have in order to form boards of the proper length.

The construction company needs desiredCount boards of length desiredLength. The have an effectively unlimited supply of boards of length actualLength. The construction company wants to use as few boards as possible. If there are multiple ways to use the same number of boards, they want to perform as few cuts as possible. Return the number of cuts they will perform.

Definition

Class:
BoardSplitting
Method:
minimumCuts
Parameters:
int, int, int
Returns:
int
Method signature:
int minimumCuts(int desiredLength, int desiredCount, int actualLength)
(be sure your method is public)

Notes

  • A board is a one-dimensional piece of wood. A single board of length L may be cut into two boards of length X and Y, provided X > 0, Y > 0, and X + Y = L. Two boards of length X and Y may be glued together to form a board of length X + Y.

Constraints

  • desiredLength will be between 1 and 1000, inclusive.
  • desiredCount will be between 1 and 1000, inclusive.
  • actualLength will be between 1 and 1000, inclusive.

Examples

  1. 5

    4

    4

    Returns: 3

    We need 4 boards of length 5 each. We have an unlimited supply of boards of length 4. One solution is to cut one board into 4 pieces of length 1 each (using 3 cuts), then glue each piece to a board of length 4.

  2. 6

    100

    3

    Returns: 0

    No cuts are necessary.

  3. 500

    5

    1000

    Returns: 3

    We cut 3 boards in half.

  4. 314

    159

    26

    Returns: 147

  5. 1

    1

    1

    Returns: 0

  6. 1

    1

    1000

    Returns: 1

  7. 1

    1000

    1

    Returns: 0

  8. 1

    1000

    1000

    Returns: 999

  9. 1000

    1

    1

    Returns: 0

  10. 1000

    1

    1000

    Returns: 0

  11. 1000

    1000

    1

    Returns: 0

  12. 1000

    1000

    1000

    Returns: 0

  13. 778

    887

    384

    Returns: 883

  14. 336

    794

    916

    Returns: 791

  15. 650

    493

    387

    Returns: 492

  16. 28

    363

    422

    Returns: 362

  17. 764

    60

    691

    Returns: 60

  18. 427

    541

    927

    Returns: 541

  19. 212

    737

    173

    Returns: 733

  20. 430

    568

    369

    Returns: 567

  21. 863

    531

    783

    Returns: 531

  22. 136

    68

    124

    Returns: 66

  23. 23

    803

    930

    Returns: 803

  24. 168

    70

    59

    Returns: 69

  25. 12

    457

    394

    Returns: 455

  26. 374

    230

    43

    Returns: 225

  27. 785

    920

    422

    Returns: 918

  28. 325

    199

    538

    Returns: 199

  29. 414

    371

    316

    Returns: 369

  30. 981

    92

    527

    Returns: 92

  31. 863

    874

    957

    Returns: 874

  32. 282

    997

    171

    Returns: 980

  33. 926

    926

    85

    Returns: 916

  34. 337

    337

    506

    Returns: 337

  35. 730

    730

    314

    Returns: 726

  36. 125

    125

    896

    Returns: 125

  37. 546

    546

    815

    Returns: 546

  38. 435

    435

    365

    Returns: 430

  39. 751

    751

    88

    Returns: 743

  40. 277

    277

    179

    Returns: 276

  41. 789

    404

    404

    Returns: 403

  42. 652

    400

    400

    Returns: 396

  43. 933

    677

    677

    Returns: 676

  44. 369

    13

    13

    Returns: 12

  45. 227

    95

    95

    Returns: 94

  46. 540

    571

    571

    Returns: 570

  47. 435

    468

    468

    Returns: 465

  48. 602

    903

    903

    Returns: 602

  49. 318

    493

    318

    Returns: 0

  50. 757

    302

    757

    Returns: 0

  51. 287

    442

    287

    Returns: 0

  52. 690

    445

    690

    Returns: 0

  53. 441

    730

    441

    Returns: 0

  54. 118

    98

    118

    Returns: 0

  55. 482

    676

    482

    Returns: 0

  56. 928

    568

    928

    Returns: 0

  57. 498

    498

    498

    Returns: 0

  58. 354

    354

    354

    Returns: 0

  59. 587

    587

    587

    Returns: 0

  60. 966

    966

    966

    Returns: 0

  61. 307

    307

    307

    Returns: 0

  62. 3

    4

    2

    Returns: 2

  63. 2

    3

    3

    Returns: 2

  64. 978

    999

    121

    Returns: 991

  65. 2

    10

    5

    Returns: 8

  66. 7

    9

    9

    Returns: 8

  67. 5

    7

    7

    Returns: 6

  68. 2

    7

    5

    Returns: 6

  69. 3

    8

    8

    Returns: 7

  70. 3

    5

    8

    Returns: 5

  71. 12

    6

    5

    Returns: 5

  72. 3

    10

    10

    Returns: 9

  73. 314

    154

    27

    Returns: 149

  74. 6

    3

    4

    Returns: 2

  75. 3

    1000

    1000

    Returns: 999

  76. 3

    60

    40

    Returns: 59

  77. 4

    13

    26

    Returns: 12

  78. 31

    511

    17

    Returns: 481

  79. 315

    159

    26

    Returns: 153

  80. 7

    3

    15

    Returns: 3

  81. 24

    159

    29

    Returns: 154

  82. 20

    3

    12

    Returns: 2

  83. 48

    1000

    500

    Returns: 992

  84. 3

    100

    4

    Returns: 75

  85. 999

    782

    567

    Returns: 745

  86. 4

    5

    5

    Returns: 4

  87. 10

    1

    3

    Returns: 1

  88. 400

    5

    1000

    Returns: 4

  89. 10

    6

    6

    Returns: 4

  90. 4

    3

    6

    Returns: 2

  91. 153

    586

    77

    Returns: 579

  92. 4

    6

    6

    Returns: 4

  93. 998

    999

    1000

    Returns: 998

  94. 4

    10

    5

    Returns: 8

  95. 987

    453

    566

    Returns: 453


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: