Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int Calc(int a, int b, vector<int> &c, int w = 0); //a = people, b = initial fruits, c = "harvest" vector, w = weeks
- int main()
- {
- int a, b, d;
- cout << "Number of people:";
- cin >> a;
- cout << endl << "Initial fruits:";
- cin >> b;
- if(a <= b)
- {
- cout << endl << "You already have enough fruits, duh";
- return 0;
- }
- vector<int> c;
- for(int _a = 0; _a < b;_a++) c.push_back(0); //fills our harvest vector
- d = Calc(a,b,c,1);
- cout << endl << "Weeks needed:" << d;
- return 0;
- }
- int Calc(int a, int b, vector<int> &c, int w) //a = people, b = fruits currently planted, c = "harvest" vector, w = weeks
- {
- ++w;
- int d = 0;
- for(int i = 0; i < b; i++)
- {
- c[i]++;
- d+= c[i];
- }
- if(d >= a) return w;
- else
- {
- for(int i = 0; i < d; i++)
- {
- c.push_back(0);
- }
- Calc(a,b+d, c, w);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement