Statistics

Problem Statement for "DinkyFish"

Problem Statement

The dinky is a small fish that breeds monogamously and regularly. Within days of its birth, the male of the species seeks out a mate and bonds with her for life, never dallying with another. At the end of every month, the couple issues exactly two offspring, of which one is a boy and the other a girl. Each of these, in turn, goes off on its amorous quest. Inbreeding is not uncommon in the confines of a fish tank, so a pair of cousins or even siblings may end up mating. If there are more females than males, the excess number who cannot secure a mate will not give birth in that month.

Despite their diminutive dimensions and peaceful nature, a population of dinkies must not be allowed to multiply ad infinitum. Experts recommend that one allot at least half a liter of water per dinky fish. Anything less than that, and the tank is said to be crowded. The solution is either to buy a larger tank or to catch some dinkies for breakfast.

Given the volume of a tank in liters, the number of male dinkies currently inhabiting the tank, and the number of females present, you are to calculate the number of months that can elapse before the tank becomes crowded. Bear in mind that all couples reproduce simultaneously at the end of every month. If the input values are such that the tank is already crowded, the correct answer is 0. If the tank will become crowded at the end of the first month, the answer is 1.

Definition

Class:
DinkyFish
Method:
monthsUntilCrowded
Parameters:
int, int, int
Returns:
int
Method signature:
int monthsUntilCrowded(int tankVolume, int maleNum, int femaleNum)
(be sure your method is public)

Notes

  • Disregard the effects of mortality. Assume that all dinkies, young and old, live perpetually.

Constraints

  • tankVolume is between 1 and 1000000 (one million), inclusive
  • maleNum is between 1 and 1000, inclusive
  • femaleNum is between 1 and 1000, inclusive

Examples

  1. 10

    4

    6

    Returns: 2

    Four couples form initially. At the end of the first month, four male and four female dinkies are born. There are now 18 dinky fish in total and eight couples. At the end of the second month, eight dinkies of each sex are born, for a total of 34, which does not allow for half a liter each in a ten-liter tank. Thus, it has taken two months to reach a crowded state.

  2. 100

    4

    6

    Returns: 5

    At the end of the fourth month, there are 130 dinky fish. At the end of the fifth, there are 258.

  3. 5

    6

    4

    Returns: 1

    A five-liter tank is just large enough for ten dinkies, but it becomes crowded at the end of the first month.

  4. 4

    6

    4

    Returns: 0

    This four-liter tank is already crowded with ten dinkies.

  5. 1000000

    3

    2

    Returns: 19

  6. 431131

    764

    249

    Returns: 11

  7. 948885

    971

    526

    Returns: 11

  8. 21506

    919

    520

    Returns: 6

  9. 118094

    183

    503

    Returns: 10

  10. 955277

    293

    477

    Returns: 12

  11. 678033

    457

    171

    Returns: 12

  12. 268744

    210

    401

    Returns: 11

  13. 327864

    227

    914

    Returns: 11

  14. 411244

    242

    31

    Returns: 14

  15. 307459

    388

    247

    Returns: 11

  16. 356731

    757

    431

    Returns: 10

  17. 291086

    218

    728

    Returns: 11

  18. 835213

    94

    714

    Returns: 14

  19. 781165

    380

    66

    Returns: 14

  20. 299824

    738

    976

    Returns: 9

  21. 700535

    808

    936

    Returns: 10

  22. 470158

    444

    194

    Returns: 12

  23. 524441

    559

    757

    Returns: 10

  24. 977161

    411

    714

    Returns: 12

  25. 204060

    262

    4

    Returns: 16

  26. 25898

    820

    553

    Returns: 6

  27. 426602

    95

    795

    Returns: 13

  28. 992799

    720

    776

    Returns: 11

  29. 669500

    391

    502

    Returns: 11

  30. 641454

    430

    574

    Returns: 11

  31. 273734

    987

    461

    Returns: 10

  32. 90626

    94

    201

    Returns: 10

  33. 812595

    404

    143

    Returns: 13

  34. 337808

    594

    110

    Returns: 12

  35. 536745

    399

    480

    Returns: 11

  36. 523748

    697

    924

    Returns: 10

  37. 513296

    760

    824

    Returns: 10

  38. 48230

    977

    477

    Returns: 7

  39. 173329

    871

    141

    Returns: 11

  40. 77533

    30

    984

    Returns: 12

  41. 141912

    710

    247

    Returns: 10

  42. 545276

    523

    847

    Returns: 11

  43. 308105

    598

    452

    Returns: 10

  44. 294032

    671

    807

    Returns: 9

  45. 557796

    607

    680

    Returns: 10

  46. 330247

    229

    959

    Returns: 11

  47. 135324

    653

    333

    Returns: 9

  48. 582323

    924

    434

    Returns: 11

  49. 749403

    353

    173

    Returns: 13

  50. 226239

    933

    673

    Returns: 9

  51. 459169

    526

    443

    Returns: 11

  52. 136628

    434

    374

    Returns: 9

  53. 35028

    722

    924

    Returns: 6

  54. 349905

    804

    779

    Returns: 9

  55. 477094

    448

    742

    Returns: 11

  56. 901631

    36

    22

    Returns: 16

  57. 540756

    482

    300

    Returns: 11

  58. 772601

    152

    343

    Returns: 13

  59. 629442

    285

    997

    Returns: 12

  60. 992741

    611

    66

    Returns: 14

  61. 28071

    31

    530

    Returns: 10

  62. 559030

    292

    325

    Returns: 11

  63. 434435

    742

    309

    Returns: 11

  64. 807007

    882

    213

    Returns: 12

  65. 896997

    930

    343

    Returns: 12

  66. 774047

    590

    211

    Returns: 12

  67. 243000

    775

    786

    Returns: 9

  68. 204537

    746

    493

    Returns: 9

  69. 920332

    399

    294

    Returns: 12

  70. 195867

    979

    767

    Returns: 8

  71. 569380

    190

    944

    Returns: 12

  72. 539794

    375

    210

    Returns: 12

  73. 676669

    379

    189

    Returns: 12

  74. 401270

    378

    123

    Returns: 12

  75. 825992

    655

    781

    Returns: 11

  76. 590151

    694

    489

    Returns: 11

  77. 881949

    895

    306

    Returns: 12

  78. 974360

    732

    184

    Returns: 13

  79. 530324

    676

    182

    Returns: 12

  80. 571512

    844

    674

    Returns: 10

  81. 561554

    417

    494

    Returns: 11

  82. 345175

    988

    406

    Returns: 10

  83. 546418

    119

    348

    Returns: 13

  84. 356267

    660

    588

    Returns: 10

  85. 308511

    554

    291

    Returns: 11

  86. 702387

    487

    432

    Returns: 11

  87. 34231

    89

    922

    Returns: 9

  88. 685142

    892

    731

    Returns: 10

  89. 312676

    194

    246

    Returns: 11

  90. 395882

    426

    254

    Returns: 11

  91. 738096

    460

    460

    Returns: 11

  92. 874816

    132

    359

    Returns: 13

  93. 576510

    761

    817

    Returns: 10

  94. 241065

    348

    66

    Returns: 12

  95. 452108

    100

    207

    Returns: 13

  96. 641295

    341

    789

    Returns: 11

  97. 324032

    511

    160

    Returns: 11

  98. 878187

    807

    644

    Returns: 11

  99. 65843

    68

    400

    Returns: 10

  100. 980453

    138

    411

    Returns: 13

  101. 30

    4

    12

    Returns: 3

  102. 40

    10

    10

    Returns: 3

  103. 1

    1

    1

    Returns: 1

  104. 1

    1

    2

    Returns: 0

  105. 1

    2

    1

    Returns: 0

  106. 10

    10

    11

    Returns: 0

  107. 100

    3

    5

    Returns: 6

  108. 431131

    764

    249

    Returns: 11

  109. 2

    1

    1

    Returns: 2

  110. 50

    50

    50

    Returns: 1

  111. 3

    1

    3

    Returns: 2

  112. 6

    6

    7

    Returns: 0

  113. 100

    40

    60

    Returns: 2

  114. 6

    6

    6

    Returns: 1

  115. 5

    6

    4

    Returns: 1

  116. 10

    6

    4

    Returns: 2

  117. 10

    9

    100

    Returns: 0

  118. 2

    2

    3

    Returns: 0

  119. 4

    4

    5

    Returns: 0

  120. 8

    12

    1

    Returns: 2

  121. 10

    2

    8

    Returns: 2

  122. 20

    1

    20

    Returns: 4

  123. 17

    4

    6

    Returns: 3

  124. 8

    9

    8

    Returns: 0


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: