Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: spagoel1
- TASK: skidesign
- LANG: C++
- */
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- #include <string>
- #include <vector>
- #include <cmath>
- using namespace std;
- int final = 0;
- int ops = 0;
- void modify(vector<int>farm) {
- ops++;
- int min, minIndex;
- min = *min_element(farm.begin(), farm.end());
- minIndex = min_element(farm.begin(), farm.end()) - farm.begin();
- cout << minIndex;
- cout << endl << min << endl;
- int max, maxIndex;
- max = *max_element(farm.begin(), farm.end());
- maxIndex = max_element(farm.begin(), farm.end()) - farm.begin();
- cout << maxIndex << endl;
- cout << max << endl;
- int diff = max - min - 17;
- cout << diff << endl;
- if (diff <= 0) {
- return;
- }
- double val = diff / 2;
- double leftover = diff - val;
- farm[minIndex] += val;
- cout << farm[minIndex] << endl;
- farm[maxIndex] -= leftover;
- cout << farm[maxIndex] << endl;
- final += pow(val,2) + pow(leftover,2);
- cout << final << endl << endl << endl;
- modify(farm);
- }
- int main () {
- ifstream i ("skidesign.in");
- vector <int> hills;
- int N;
- int temp;
- i >> N;
- cout << N << endl;
- for (int x = 0; x <= N; x++) {
- i >> temp;
- hills.push_back(temp);
- }
- i.close();
- hills.pop_back();
- cout << hills.size() << endl;
- modify(hills);
- cout << endl << ops;
- ofstream o ("skidesign.out");
- o << to_string(final) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement