LightOJ - 1166
Description Given an array containing a permutation of 1 to n, you have to find the minimum number of swaps to sort the array in ascending order. A swap means, you can exchange any two elements of the array. For example, let n = 4, and the array be 4 2 3 1, then you can sort it in ascending order in just 1 swaps (by swapping 4 and 1). Input Input starts with an integer T (≤ 100), denoting the number of test cases. Each case contains two lines, the first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers separated by spaces. You may assume that the array will always contain a permutation of 1 to n. Output For each case, print the case number and the minimum number of swaps required to sort the array in ascending order. Sample Input 3 4 4 2 3 1 4 4 3 2 1 4 1 2 3 4 Sample Output Case 1: 1 Case 2: 2 Case 3: 0 Source
Problem Setter: Jane Alam Jan
//题意:
给你n个数,和这n个数的序列,可以两两交换,问把它们变换为从小到大的序列,最少变换几次?
//思路:
就是一个简单的置换群,没啥说的
|
LightOJ - 1166 Old Sorting (置换群)
最新推荐文章于 2017-07-05 11:08:02 发布