题目:求逆序数。
分析:简单题。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int D[ 65 ];
int main()
{
int N,L;
while ( scanf("%d",&N) != EOF )
while ( N -- ) {
scanf("%d",&L);
for ( int i = 1 ; i <= L ; ++ i )
scanf("%d",&D[i]);
int ans = 0;
for ( int i = 1 ; i <= L ; ++ i )
for ( int j = i+1 ; j <= L ; ++ j )
if ( D[i] > D[j] ) ++ ans;
printf("Optimal train swapping takes %d swaps.\n",ans);
}
return 0;
}