Korotkodul

B-Паркур

Oct 22nd, 2021 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <map>
  6. #include <set>
  7. #include <string>
  8. #include <stdio.h>
  9. #include <sstream>
  10. #include <iomanip>
  11. using namespace std;
  12. using ll = long long;
  13.  
  14. vector <int> h;
  15.  
  16. int cl(int i, int j) {
  17.     if (!(i >= 0 && i < (int)h.size() && j >= 0 && j < (int)h.size())) {
  18.         return 666;
  19.     }
  20.     else return abs(i - j) + h[j] - h[i];
  21.     //return abs(i - j) + h[j] - h[i];
  22. }
  23. void co(vector <int> v) {
  24.     for (auto& x : v) cout << x << ' ';
  25.     cout << '\n';
  26. }
  27. int N;
  28. int cnt(vector <int> v) {
  29.     int res = 0;
  30.     for (int i = 0; i < N - 1; ++i) {
  31.         int pl = cl(v[i], v[i + 1]);
  32.         if (pl == 666) {
  33.             cout << "BUG BAD INDEX\n";
  34.             cout << "v[i] = " << v[i] << "  v[i+1] = " << v[i+1]<<"\n";
  35.             if (v[i] >= 0  && v[i] < (int)v.size()){
  36.                 cout<<"high = "<<h[v[i]]<<'\n';
  37.             }
  38.             //cout<<"h[v[i]] = "<<h[v[i]]<<"  h[v[i+1]] = "<<h[v[i+1]]<<'\n';
  39.             }
  40.         res += pl;
  41.     }
  42.     return res;
  43. }
  44.  
  45.  
  46. int main()
  47. {
  48.     ios_base::sync_with_stdio(false);
  49.     cin.tie(0);
  50.     int n;
  51.     cin >> n;
  52.     N = n;
  53.     vector <int> h;
  54.     h.resize(n);
  55.     vector <int> v;
  56.     cout << "size h = " << h.size() << '\n';
  57.     for (int i = 0; i < n; ++i) {
  58.         cin >> h[i];
  59.         v.push_back(i);
  60.     }
  61.     co(h);
  62.     int max = -100;
  63.     int tot = -99;
  64.     vector <int> be;
  65.     do {
  66.         tot = cnt(v);
  67.         co(v);
  68.         //cout << tot << '\n'<<'\n';
  69.         if (tot > max) {
  70.             //cout << tot << '\n';
  71.             be = v;
  72.             max = tot;
  73.         }//cout << '\n';
  74.     } while (next_permutation(v.begin(), v.end()));
  75.     cout << max << '\n';
  76.     //cout << "b\n";
  77.     //co(be);
  78.     //ch(b);
  79. }
  80.  
Add Comment
Please, Sign In to add comment