Chang Shen’s Problem 1(思路,矩阵多次打乱)

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行列找出原来对应的元素位置即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值