Matrix

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 271    Accepted Submission(s): 126

Problem Description
There is a matrix M

that has n

rows and m

columns (1≤n≤1000,1≤m≤1000)

.Then we perform q(1≤q≤100,000)

operations:

1 x y: Swap row x and row y (1≤x,y≤n)

;

2 x y: Swap column x and column y (1≤x,y≤m)

;

3 x y: Add y to all elements in row x (1≤x≤n,1≤y≤10,000)

;

4 x y: Add y to all elements in column x (1≤x≤m,1≤y≤10,000)

;

 
Input
There are multiple test cases. The first line of input contains an integer T(1≤T≤20)

indicating the number of test cases. For each test case:

The first line contains three integers n

, m

and q

.
The following n

lines describe the matrix M.(1≤Mi,j≤10,000)

for all (1≤i≤n,1≤j≤m)

.
The following q

lines contains three integers a(1≤a≤4)

, x

and y

.

 
Output
For each test case, output the matrix M

after all q

operations.

 
Sample Input
2
3 42
1 2 3 4
2 3 4 5
3 4 5 6
1 1 2
3 1 10
2 2 2
1 10
10 1
1 1
2
2
1 2
 
Sample Output
12 13 14 15
1 2 3 4
3 4 5 6
1 10
10 1

Hint

Recommand to use scanf and printf

 
Source
 
题意:对矩阵执行q次  4种类型的操作 输出 最终矩阵
 
题解:

对于交换行、交换列的操作,分别记录当前状态下每一行、每一列是原始数组的哪一行、哪一列即可。

对每一行、每一列加一个数的操作,也可以两个数组分别记录。注意当交换行、列的同时,也要交换增量数组。

输出时通过索引找到原矩阵中的值,再加上行、列的增量

  #include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define LL __int64
#define pi acos(-1.0)
#define mod 1
#define maxn 10000
using namespace std;
int t;
int mp[][] ;
int n,m,q;
int a,x,y;
int l[],h[];
int ladd[],hadd[];
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d %d %d",&n,&m,&q);
for(int j=;j<=n;j++)
for(int k=;k<=m;k++)
scanf("%d",&mp[j][k]);
for(int j=;j<=n;j++)
{
h[j]=j;hadd[j]=j;
}
for(int j=;j<=m;j++)
{
l[j]=j; ladd[j]=;
}
memset(hadd,,sizeof(hadd));
memset(ladd,,sizeof(ladd));
int t;
for(int j=;j<=q;j++)
{
scanf("%d %d %d",&a,&x,&y);
if(a==)
{
t=h[y];
h[y]=h[x];
h[x]=t;
}
else
if(a==)
{
t=l[y];
l[y]=l[x];
l[x]=t;
}
else
if(a==)
{
hadd[h[x]]+=y;
}
else
ladd[l[x]]+=y;
}
for(int j=;j<=n;j++)
{
printf("%d",mp[h[j]][l[]]+hadd[h[j]]+ladd[l[]]);
for(int k=;k<=m;k++)
{
printf(" %d",mp[h[j]][l[k]]+hadd[h[j]]+ladd[l[k]]);
}
printf("\n");
}
}
return ;
}
 
 

最新文章

  1. jquery的全选插件
  2. C#之方法的重载与递归
  3. 【Win10 UWP】后台任务与动态磁贴
  4. NET基础(2):类型转换
  5. 第一个python程序hello.py
  6. asp存储过程
  7. WF学习
  8. PHP学习笔记二十四【Get Set】
  9. Div 滚动栏滚动到指定的位置
  10. select into from 和 insert into select 的用法
  11. android BLE Peripheral 模拟 ibeacon 发出ble 广播
  12. pdf生成库-libharu编译
  13. JSP:getOutputStream() has already been called for this response
  14. MT【255】伸缩变换
  15. ThinkPHP5基础学习(慕课版)
  16. [laravel]malformed header from script &#39;index.php&#39;: Bad header: HTTP/1.1 302 Found, referer: http://localhost/auth/login
  17. Lucene实战之基于StandardAnalyzer读写索引
  18. Docker容器学习梳理 - 容器硬盘热扩容
  19. Codeforces 260B - Ancient Prophesy
  20. 【微信小程序推广营销】教你微信小程序SEO优化,让你的小程序快人一步抢占先机

热门文章

  1. WordPress4.9 最新版本网站安全漏洞详情与修复
  2. centos 安装java1.8
  3. 分享一个工作中遇得到的sql(按每天每人统计拖车次数与小修次数)
  4. 50-Identity MVC:DbContextSeed初始化
  5. Android Studio modify language level to Java 8
  6. 3155: Preprefix sum
  7. 深度学习:激活函数的比较和优缺点,sigmoid,tanh,relu
  8. Java工程师笔试题整理[校招篇]
  9. python保留关键字和常用关键字
  10. 「日常训练」「小专题·图论」 Frogger (1-1)