SHARE
TWEET

Untitled

a guest Nov 12th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <cmath>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. ofstream out;
  11.  
  12. int a;
  13. double tmp;
  14.  
  15. double mtrx[100][2];
  16. vector <float> our_coord;
  17.  
  18. void pushVector();
  19. void fillMatrix();
  20. void workWithMltrix();
  21.  
  22. int main() {
  23.    
  24.  
  25.     freopen("in.txt", "r", stdin);
  26.    
  27.    
  28.     cin >> a;
  29.    
  30.     pushVector();
  31.     fillMatrix();
  32.  
  33.     mtrx[1][0] = 0;
  34.     mtrx[1][1] = abs(our_coord[0] - our_coord[1]);
  35.  
  36.     workWithMltrix();
  37.  
  38.     out.open("out.txt");
  39.     out << fixed;
  40.     out << setprecision(2) << mtrx[a - 1][1];
  41.     out.close();
  42.  
  43.     return 0;
  44. }
  45.  
  46. void pushVector() {
  47.     int i = 0;
  48.  
  49.     while (i < a) {
  50.         i++;
  51.         cin >> tmp;
  52.         our_coord.push_back(tmp);
  53.     }
  54. }
  55.  
  56. void fillMatrix() {
  57.    
  58.     int i = 0;
  59.  
  60.     while (i < a) {
  61.         i++;
  62.         mtrx[i][0] = 1000;
  63.         mtrx[i][1] = 1000;
  64.     }
  65. }
  66.  
  67. void workWithMltrix() {
  68.  
  69.     for (int i = 1; i < a - 1; i++) {
  70.         mtrx[i][0] = mtrx[i - 1][1];
  71.         mtrx[i + 1][1] = fmin(mtrx[i][0], mtrx[i][1]) + ( abs(our_coord[i] - our_coord[i + 1]));
  72.     }
  73. }
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