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

思维~

#include
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;
} 

 

你可能感兴趣的:(ZOJ4104 Sequence in the Pocket(2019浙江省赛))