把一个序列按从小到大排序 要执行多少次操作
只需要从右往左统计,并且不断更新最小值,若当前数为最小值,则将最小值更新为当前数,否则sum+1
Sample Input
2
5
5 4 3 2 1
5
5 1 2 3 4
Sample Output
Case #1: 4
Case #2: 1
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# include <list>
# define LL long long
using namespace std ; const int INF=0x3f3f3f3f; int a[] ; int main()
{
//freopen("in.txt","r",stdin) ;
int T ;
scanf("%d" , &T) ;
int Case = ;
while(T--)
{
Case++ ;
int n , i , j;
scanf("%d" , &n) ;
for (i = ; i < n ; i++)
scanf("%d" , &a[i]) ;
int sum = ;
int MIN = INF ;
for (i = n- ; i >= ; i--)
{
if (a[i] < MIN)
MIN = a[i] ;
else
sum++ ;
}
printf("Case #%d: %d\n" , Case , sum) ; } return ;
}