问题是给出一个数组,然后数组里面的元素可以交换,任意位置都可以交换,然后求使得该数组有序的最小交换次数。
课上做到一道题,就是这个意思,描述如下:
Description
Given an array of N distinct elementsA[ ], find the minimum number of swaps required to sort the array.Your are required to complete the function which returns an integer denoting the minimum number of swaps, required to sort the array.
Input
The first line of input contains an integer T denoting the no of test cases . Then T test cases follow . Each test case contains an integer N denoting the no of element of the array A[ ]. In the next line are N space separated values of the array A[ ] .(1<=T<=100;1<=N<=100;1<=A[] <=1000)
Output
For each test case in a new line output will be an integer denoting minimum umber of swaps that are required to sort the array.
Sample Input 1
2
4
4 3 2 1