FleasFleas
TCCC '03 W/MW Regional · 2003-02-20 · by dgoodman
Problem Statement
Assume that every infested creature (either a dog or a flea) is infested with n fleas and that k of these are themselves infested (with smaller fleas). At each smaller size, n stays the same but k decreases by 5 (but never becomes negative).
For example, suppose that n is 30 and k is originally 7. Then my dog is infested by 30 fleas of which 7 are infested with tiny fleas. Each of those 7 is infested with 30 tiny fleas of which 2 are infested with 30 miniscule fleas. No miniscule flea is infested (since 2-5 is not positive). Calculating the entire population we get 23 uninfested fleas + 7 infested fleas + 196 uninfested tiny fleas + 14 infested tiny fleas + 420 minuscule uninfested fleas = 660 fleas of all sizes.
Create a class FleasFleas that contains method population that takes an int n, the number of full-sized fleas on my dog, and an int k, the number of those that are themselves infested, and returns the total flea population on my dog. If the population is more than 10,000,000 return -1.
Constraints
- n is between 1 and 100 inclusive
- k is between 0 and n inclusive
30 7 Returns: 660
As described in the Problem Statement
100 3 Returns: 400
There are 100 full-sized fleas, 3 of which have 100 tiny fleas each
100 100 Returns: -1
50 15 Returns: 45800
50 14 Returns: 32250
Submissions are judged against all 29 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FleasFleas with a public method int population(int n, int k) · 29 test cases · 2 s / 256 MB per case