Advertisement
Guest User

Challenge #242 - Easy

a guest
Dec 17th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int Calc(int a, int b, vector<int> &c, int w = 0); //a = people, b = initial fruits, c = "harvest" vector, w = weeks
  7.  
  8. int main()
  9. {
  10.     int a, b, d;
  11.     cout << "Number of people:";
  12.     cin >> a;
  13.     cout << endl << "Initial fruits:";
  14.     cin >> b;
  15.     if(a <= b)
  16.     {
  17.         cout << endl << "You already have enough fruits, duh";
  18.         return 0;
  19.     }
  20.  
  21.     vector<int> c;
  22.  
  23.     for(int _a = 0; _a < b;_a++) c.push_back(0); //fills our harvest vector
  24.  
  25.     d = Calc(a,b,c,1);
  26.     cout << endl << "Weeks needed:" << d;
  27.  
  28.     return 0;
  29. }
  30.  
  31. int Calc(int a, int b, vector<int> &c, int w) //a = people, b = fruits currently planted, c = "harvest" vector, w = weeks
  32. {
  33.     ++w;
  34.     int d = 0;
  35.     for(int i = 0; i < b; i++)
  36.     {
  37.         c[i]++;
  38.         d+= c[i];
  39.     }
  40.     if(d >= a) return w;
  41.     else
  42.     {
  43.         for(int i = 0; i < d; i++)
  44.         {
  45.             c.push_back(0);
  46.         }
  47.         Calc(a,b+d, c, w);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement