2011年11月18日 星期五

331 - Mapping the Swaps

藉由不斷地對兩個陣列元素作交換以完成陣列元素的排序,這種方法是眾所皆知的「泡泡排序法」(bubble sort) 所用的方式。本題請你計算對於一個陣列共有幾種不同的最小置換順序,例如對3 2 1作排序共有兩種不同的置換順序,分別為:
1. 321 -> 231 -> 213 -> 123。
2. 321 -> 312 -> 132 -> 123。

Input

輸入會有多組測試資料,每組資料的第一個整數表示該陣列元素的個數 n,接下來依序為 n 個元素值。

Output

請參考範例資料輸出每組測試資料共有幾種不同的置換順序,並輸出測試資料編號,注意 n 最大值為5。

Sample Input

2 9 7
2 12 50
3 3 2 1
3 9 1 5
0

Sample Output

There are 1 swap maps for input data set 1.
There are 0 swap maps for input data set 2.
There are 2 swap maps for input data set 3.
There are 1 swap maps for input data set 4.

原文出處

沒有留言:

張貼留言