Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line andn is the number of students in the line. The children find it hard to keep in mind this strange arrangement, and today they formed the line in the following order: b1, b2, ..., bn, which upset Vasya immensely. Now Vasya wants to rearrange the children so that the resulting order is like this: a1, a2, ..., an. During each move Vasya can swap two people who stand next to each other in the line. Help Vasya, find the sequence of swaps leading to the arrangement Vasya needs. It is not required to minimize the number of moves.
The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integersai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent the height of the student occupying the i-th place in the initial arrangement. It is possible that some students possess similar heights. It is guaranteed that it is possible to arrange the children in the required order, i.e. aand b coincide as multisets.
In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1.
4
1 2 3 2
3 2 1 2
4
2 3
1 2
3 4
2 3
2
1 100500
1 100500
0
1 /****************************** 2 AC 3 date£º2013-10-9-19:00 4 *********************************/ 5 #include <iostream> 6 #include<stdio.h> 7 #include<string.h> 8 #include<math.h> 9 int a[302]; 10 int b[302]; 11 int sw1[1000003]; 12 int sw2[1000003]; 13 using namespace std; 14 15 int main() 16 { 17 int n; 18 while(scanf("%d",&n)!=EOF) 19 { 20 /*输入初始的顺序*/ 21 for(int i=1; i<=n; i++) 22 { 23 scanf("%d",&a[i]); 24 } 25 /*输入当前的顺序*/ 26 for(int i=1;i<=n;i++) 27 { 28 scanf("%d",&b[i]); 29 } 30 int d,j,i,t; 31 int num=0; 32 for(i=1; i<=n; i++) 33 { 34 for(j=i; j<=n; j++) 35 { 36 if(b[j]==a[i])//在当前队列中找到与初始队列中第i个数相同的数, 37 { 38 d=j; 39 while(d!=i)//通过位置交换把当前队列中的数换到初始队列所在的位置 40 { 41 t=b[d]; 42 b[d]=b[d-1]; 43 b[d-1]=t; 44 //printf("%d %d ",d-1,d); 45 sw1[num]=d-1;//保存交换操作步骤 46 sw2[num]=d; 47 num++;//统计交换次数 48 d--; 49 } 50 break; 51 } 52 } 53 } 54 printf("%d ",num); 55 //输出 56 for(i=0;i<num;i++) 57 { 58 printf("%d %d ",sw1[i],sw2[i]); 59 } 60 61 } 62 return 0; 63 }