陕西师范大学第七届程序设计竞赛网络同步赛 排队排队排队

题目链接

类似于最长公共子序列,只不过这题只能把人往队首掉,比较相似。

#include <bits/stdc++.h>
using namespace std;
int main(){
     int n, sum=0, a[SIZE], b[SIZE];
     cin >> n;
     for ( int i=0; i<n; ++i){
         cin >> a[i];
         b[i] = a[i];
     }
     sort(b, b + n);
     for ( int i=n-1, j=n-1; i>=0; --i){
         if (a[i] == b[j]){
             --j, ++sum;
         }
     }
     cout << n-sum << endl;
     return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41603898/article/details/80303645