Chang Shen’s Problem 1
Given a matrix of size n*m(1<=n*m<=1e6).Chang Shen will ask you to do q operations, each of the operation is described by (op,x,y).
If op==0,then you should exchange the x row and the y row of the matrix.
If op==1,then you should exchange the x column and the y column of the matrix.
Input
First line contains an integer T(T<=10) which is the total number of test cases.For each test case,first line contains n,m,q as described above(1<=n*m<=1e6,0
Output
For each test cases,output the matrix after the q operations.Please output an empty line between test cases.
Sample Input
2
2 3 1
1 4 2
2 3 1
1 1 3
3 3 2
1 2 3
4 5 6
7 8 9
0 1 3
1 2 3
Sample Output
2 4 1
1 3 2
7 9 8
4 6 5
1 3 2
思路:
每行每列初始化自己的位置:
c[1]=1,c[2]=2,……,c[n]=n
r[1]=1,r[2]=2,……,r[n]=n
每次交换行列时,将其对应的数字交换,最后按照a[i],c[j]对应的n,m行列找出原来对应的元素位置即可