Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <climits>
- using namespace std;
- //Class for the Various ages;
- class Fe{
- public:
- int Age;
- int Num;
- Fe(int age, int num){
- Age = age;
- Num = num;
- }
- };
- //Class and methods for the Expedition!;
- class Trip{
- public:
- int baby,years,Cap;
- vector<Fe*> psgO;
- Trip(vector<Fe*> P, int Y, int C){
- psgO = P;
- years = Y;
- Cap = C;
- }
- void Simulation(){
- int exp = 0;
- int succ =2;
- int min= INT_MAX;
- int max= 0;
- vector<Fe*> psg = psgO;
- //Starts Simulation (never gets out -.-);
- while(succ!=1){
- int flag=1;
- //cycle where the simulation of one journey begins;
- //aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- for(int i=0; i<=years; i++){
- baby=0;
- //Goes through all ages;
- for(int j=0; j<psg.size(); j++){
- //Kills the ones that exceed the expectancy
- if(psg[j]->Age >= exp){
- psg.erase (psg.begin()+j);
- j--;
- }
- //Adds to the ages +1 year, decides if they are fertile;
- else{
- psg[j]->Age++;
- if(psg[j]->Age >= 20 && psg[j]->Age <= exp/2){
- baby += psg[j]->Num;
- }
- //cout << psg[j]->Age << " " << psg[j]->Num << endl;
- }
- }
- //adds the new babies!!;
- if(baby >= 10){
- psg.push_back(new Fe(0,baby/10));
- }
- }
- //calculates the total of the survivors;
- int tot=0;
- for(int q=0; q<psg.size(); q++){
- tot += psg[q]->Num;
- }
- //clears psg (passangers) and adds the initial ones again
- psg.clear();
- for(int k=0; k<psgO.size(); k++){
- psg.push_back(psgO[k]);
- }
- //checks is the total of survivors is whithin the Success limits;
- if(tot >= 200 && tot <= Cap){
- flag = 1;
- }else{
- flag = 0;
- }
- //aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- //cycle ends here;
- //checking if Max and Min are already found;
- if(flag == 1){
- if(exp >= max){
- max = exp;
- }
- if(exp <= min){
- min = exp;
- succ=0;
- }
- }
- else{
- succ++;
- }
- exp++;
- }
- //prints the result; (never gets here -.- )
- cout << min << " " << max << endl;
- }
- };
- int main()
- {
- //pre-builded parser;
- int Y;
- cin >> Y; cin.ignore();
- int C;
- cin >> C; cin.ignore();
- int N;
- cin >> N; cin.ignore();
- //Array of various Ages;
- vector<Fe*> psg;
- //Reads Array of ages;
- for (int i = 0; i < N; i++) {
- int Age;
- int Num;
- cin >> Age;
- cin >> Num;
- psg.push_back(new Fe(Age,Num));
- }
- //Sets the conditions for the Expedition;
- Trip* ship = new Trip(psg,Y,C);
- //Initiates Simulation to decide Min and Max life expectancy;
- ship->Simulation();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement