Advertisement
Guest User

To Sky's Edge

a guest
Dec 22nd, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <climits>
  6.  
  7. using namespace std;
  8.  
  9. //Class for the Various ages;
  10. class Fe{
  11. public:
  12.   int Age;
  13.   int Num;
  14.  
  15.   Fe(int age, int num){
  16.     Age = age;
  17.     Num = num;
  18.   }
  19. };
  20.  
  21. //Class and methods for the Expedition!;
  22. class Trip{
  23. public:
  24.   int baby,years,Cap;
  25.   vector<Fe*> psgO;
  26.  
  27.   Trip(vector<Fe*> P, int Y, int C){
  28.     psgO = P;
  29.     years = Y;
  30.     Cap = C;
  31.   }
  32.  
  33.  
  34.   void Simulation(){
  35.     int exp = 0;
  36.     int succ =2;
  37.     int min= INT_MAX;
  38.     int max= 0;
  39.     vector<Fe*> psg = psgO;
  40.  
  41.     //Starts Simulation (never gets out -.-);
  42.     while(succ!=1){
  43.       int flag=1;
  44.  
  45.       //cycle where the simulation of one journey begins;
  46.       //aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa    
  47.       for(int i=0; i<=years; i++){
  48.     baby=0;
  49.  
  50.     //Goes through all ages;
  51.     for(int j=0; j<psg.size(); j++){
  52.  
  53.       //Kills the ones that exceed the expectancy
  54.       if(psg[j]->Age >= exp){
  55.        
  56.         psg.erase (psg.begin()+j);
  57.         j--;
  58.        
  59.       }
  60.       //Adds to the ages +1 year, decides if they are fertile;
  61.       else{
  62.         psg[j]->Age++;
  63.         if(psg[j]->Age >= 20 && psg[j]->Age <= exp/2){
  64.           baby += psg[j]->Num;
  65.         }
  66.         //cout << psg[j]->Age << " " << psg[j]->Num << endl;
  67.       }
  68.     }
  69.  
  70.     //adds the new babies!!;
  71.     if(baby >= 10){
  72.       psg.push_back(new Fe(0,baby/10));
  73.     }
  74.    
  75.       }
  76.  
  77.      
  78.       //calculates the total of the survivors;
  79.       int tot=0;
  80.       for(int q=0; q<psg.size(); q++){
  81.     tot += psg[q]->Num;
  82.       }
  83.  
  84.       //clears psg (passangers) and adds the initial ones again
  85.       psg.clear();
  86.       for(int k=0; k<psgO.size(); k++){
  87.     psg.push_back(psgO[k]);
  88.       }
  89.  
  90.       //checks is the total of survivors is whithin the Success limits;
  91.       if(tot >= 200 && tot <= Cap){
  92.     flag = 1;
  93.       }else{
  94.     flag = 0;
  95.       }
  96.      
  97.       //aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  98.       //cycle ends here;
  99.  
  100.  
  101.       //checking if Max and Min are already found;
  102.      
  103.       if(flag == 1){
  104.     if(exp >= max){
  105.       max = exp;
  106.     }
  107.     if(exp <= min){
  108.       min = exp;
  109.       succ=0;
  110.     }
  111.       }
  112.       else{
  113.     succ++;
  114.       }
  115.       exp++;
  116.     }
  117.    
  118.     //prints the result; (never gets here -.- )
  119.     cout << min << " " << max << endl;
  120.   }
  121.                
  122.                
  123. };
  124.  
  125.  
  126. int main()
  127. {
  128.   //pre-builded parser;
  129.   int Y;
  130.   cin >> Y; cin.ignore();
  131.   int C;
  132.   cin >> C; cin.ignore();
  133.   int N;
  134.   cin >> N; cin.ignore();
  135.   //Array of various Ages;
  136.   vector<Fe*> psg;
  137.  
  138.  
  139.   //Reads Array of ages;
  140.   for (int i = 0; i < N; i++) {
  141.     int Age;
  142.     int Num;
  143.     cin >> Age;
  144.     cin >> Num;
  145.     psg.push_back(new Fe(Age,Num));
  146.   }
  147.  
  148.   //Sets the conditions for the Expedition;
  149.   Trip* ship = new Trip(psg,Y,C);
  150.  
  151.   //Initiates Simulation to decide Min and Max life expectancy;
  152.   ship->Simulation();
  153.                      
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement