Problem Statement
As a serious strategy-games player, you know how important it is to gather enough food for your army before any invasion. Because of this, you decided
to collect at least neededFood units of food for your soldiers.
At the beginning, you have n workers to help you. In a single round, each of your workers gathers one unit of food. At the end of each round, you can trade some of your food for new workers. Hiring a single new worker costs price units of food. You can purchase any amount of new workers as long as you have the food to pay for it.
Return the minimum number of rounds you need to gather at least neededFood units of food.
At the beginning, you have n workers to help you. In a single round, each of your workers gathers one unit of food. At the end of each round, you can trade some of your food for new workers. Hiring a single new worker costs price units of food. You can purchase any amount of new workers as long as you have the food to pay for it.
Return the minimum number of rounds you need to gather at least neededFood units of food.
Definition
- Class:
- FoodCollecting
- Method:
- gather
- Parameters:
- long, int, int
- Returns:
- int
- Method signature:
- int gather(long neededFood, int n, int price)
- (be sure your method is public)
Constraints
- neededFood, n and price will each be between 1 and 1000, inclusive.