Initial commit
This commit is contained in:
58
2019/republic/12_d2/vasul.cpp
Normal file
58
2019/republic/12_d2/vasul.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <deque>
|
||||
#include <numeric>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ifstream input_stream;
|
||||
ofstream output_stream;
|
||||
|
||||
|
||||
uint64_t dequeSum(deque<uint64_t> &d) {
|
||||
return accumulate(d.begin(), d.end(), 0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
input_stream.open("input.txt");
|
||||
output_stream.open("output.txt");
|
||||
|
||||
uint16_t P, T, N;
|
||||
input_stream >> P;
|
||||
input_stream >> T;
|
||||
input_stream >> N;
|
||||
|
||||
deque<uint64_t> bacteria;
|
||||
bacteria.push_front(P);
|
||||
|
||||
uint16_t i;
|
||||
uint64_t mature = 0;
|
||||
|
||||
// Populate list until death of first generation
|
||||
for (i=1; i < T && i <= N; i++) {
|
||||
// Reproduction
|
||||
bacteria.push_front(mature);
|
||||
|
||||
// Maturity
|
||||
mature += bacteria[1];
|
||||
}
|
||||
|
||||
// Run loop considering death until experiment is complete
|
||||
for(i; i <= N; i++) {
|
||||
// Reproduction
|
||||
bacteria.push_front(mature);
|
||||
|
||||
// Death
|
||||
mature -= bacteria.back();
|
||||
bacteria.pop_back();
|
||||
|
||||
// Maturity
|
||||
mature += bacteria[1];
|
||||
}
|
||||
|
||||
output_stream << dequeSum(bacteria) << endl;
|
||||
|
||||
input_stream.close();
|
||||
output_stream.close();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user