2 条题解

  • 0
    @ 2026-8-6 10:18:34
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n; cin >> n;
        vector<int> vec0, vec1, vec2;
        for (int i = 1; i <= n; i++) vec0.push_back(i);
        for (int i = 1, x; i <= n; i++) cin >> x, vec1.push_back(x);
        for (int i = 1, x; i <= n; i++) cin >> x, vec2.push_back(x);
        int cnt1 = 0, cnt2 = 0;
        while (vec1 != vec0) prev_permutation(vec1.begin(), vec1.end()), cnt1 ++;
        while (vec2 != vec0) prev_permutation(vec2.begin(), vec2.end()), cnt2 ++;
        cout << abs(cnt1 - cnt2);
        return 0;
    }
    
    • 0
      @ 2026-7-16 8:56:49
      #include <bits/stdc++.h>
      
      using namespace std;
      
      int main() {
        int n;
        cin >> n;
      
        vector<int> p(n);
        vector<int> q(n);
      
        for (int i = 0; i < n; i++) {
          cin >> p[i];
        }
        for (int i = 0; i < n; i++) {
          cin >> q[i];
        }
      
        if (p > q) {
          swap(p, q);
        }
        int cnt = 0;
        while (p != q) {
          next_permutation(p.begin(), p.end());
          cnt++;
        }
        cout << cnt << "\n";
        return 0;
      }
      
      
      • 1

      【STL:next_permutation】[ABC150C] Count Order

      信息

      ID
      11796
      时间
      2000ms
      内存
      1024MiB
      难度
      6
      标签
      递交数
      82
      已通过
      27
      上传者