ZOJ4104 Sequence in the Pocket(2019浙江省赛)

思维~

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+14;
int a[maxn];
int b[maxn];
int N;
int main () {
    int T;
    scanf ("%d",&T);
    while (T--) {
        scanf ("%d",&N);
        for (int i=1;i<=N;i++) {
            scanf ("%d",&a[i]);
            b[i]=a[i];
        }
        sort (b+1,b+N+1);
        int ans=0;
        for (int i=N;i>=1;i--) {
            if (a[i]==b[i+ans]) continue;
            else ans++;
        }
        printf ("%d\n",ans);
    }
    return 0;
} 

 

posted @ 2020-02-13 14:57  zlc0405  阅读(98)  评论(0编辑  收藏  举报