SHARE
TWEET

skicoursedesign

Spandan14 Jul 16th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ID: spagoel1
  3. TASK: skidesign
  4. LANG: C++
  5.  */
  6. #include <iostream>
  7. #include <fstream>
  8. #include <algorithm>
  9. #include <string>
  10. #include <vector>
  11. #include <cmath>
  12. using namespace std;
  13. int final = 0;
  14. int ops = 0;
  15. void modify(vector<int>farm) {
  16.   ops++;
  17.   int min, minIndex;
  18.   min = *min_element(farm.begin(), farm.end());
  19.   minIndex = min_element(farm.begin(), farm.end()) - farm.begin();
  20.   cout << minIndex;
  21.   cout << endl << min << endl;
  22.   int max, maxIndex;
  23.   max = *max_element(farm.begin(), farm.end());
  24.   maxIndex = max_element(farm.begin(), farm.end()) - farm.begin();
  25.   cout << maxIndex << endl;
  26.   cout << max << endl;
  27.   int diff = max - min - 17;
  28.   cout << diff << endl;
  29.   if (diff <= 0) {
  30.     return;
  31.   }
  32.   double val = diff / 2;
  33.   double leftover = diff - val;
  34.   farm[minIndex] += val;
  35.   cout << farm[minIndex] << endl;
  36.   farm[maxIndex] -= leftover;
  37.   cout << farm[maxIndex] << endl;
  38.   final += pow(val,2) + pow(leftover,2);
  39.   cout << final << endl << endl << endl;
  40.   modify(farm);
  41.  
  42. }
  43. int main () {
  44.   ifstream i ("skidesign.in");
  45.   vector <int> hills;
  46.   int N;
  47.   int temp;
  48.   i >> N;
  49.   cout << N << endl;
  50.   for (int x = 0; x <= N; x++) {
  51.     i >> temp;
  52.     hills.push_back(temp);
  53.   }
  54.   i.close();
  55.   hills.pop_back();
  56.   cout << hills.size() << endl;
  57.   modify(hills);
  58.   cout << endl << ops;
  59.   ofstream o ("skidesign.out");
  60.   o << to_string(final) << endl;
  61.   return 0;
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top