#Description
K.Bro发明了一种排序
每次随机挑一个数
然后往后冒泡
为了简化问题,这些数是1 ~ N
现在给一列数 问要几轮K.Bro Sorting
e.g.
5 4 3 2 1 要 4 轮
5 1 2 3 4 要 1 轮
#Algorithm
从后往前
比如如果出现了 比后面比前面小这种情况 那肯定是要一次的
#Code
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 3e6 + 9;
int a[maxn];
void solve()
{
memset(a, 0, sizeof(a));
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
int t = a[n - 1];
int ans = 0;
for (int i = n - 2; i >= 0; i--)
if (a[i] > t) ans++;
else t = a[i];
printf("%d\n", ans);
}
int main()
{
int t;
scanf("%d", &t);
for (int i = 1; i <= t; i++)
{
printf("Case #%d: ", i);
solve();
}
}