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 ;
}
 
 

HDU 5671 矩阵的更多相关文章

  1. hdu 4291 矩阵幂 循环节

    http://acm.hdu.edu.cn/showproblem.php?pid=4291 凡是取模的都有循环节-----常数有,矩阵也有,并且矩阵的更奇妙: g(g(g(n))) mod 109  ...

  2. HDU 5671 Matrix 水题

    Matrix 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5671 Description There is a matrix M that has ...

  3. HDU 2855 (矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2855 题目大意:求$S(n)=\sum_{k=0}^{n}C_{n}^{k}Fibonacci(k)$ ...

  4. HDU 4471 矩阵快速幂 Homework

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4471 解题思路,矩阵快速幂····特殊点特殊处理····· 令h为计算某个数最多须知前h个数,于是写 ...

  5. HDU - 1575——矩阵快速幂问题

    HDU - 1575 题目: A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973.  Input数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n( ...

  6. hdu 1757 (矩阵快速幂) 一个简单的问题 一个简单的开始

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1757 题意不难理解,当x小于10的时候,数列f(x)=x,当x大于等于10的时候f(x) = a0 * ...

  7. HDU 2157 矩阵幂orDP

    How many ways?? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. 随手练——HDU 5015 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5015 看到这个限时,我就知道这题不简单~~矩阵快速幂,找递推关系 我们假设第一列为: 23 a1 a2 ...

  9. HDU 3802 矩阵快速幂 化简递推式子 加一点点二次剩余知识

    求$G(a,b,n,p) = (a^{\frac {p-1}{2}}+1)(b^{\frac{p-1}{2}}+1)[(\sqrt{a} + \sqrt{b})^{2F_n} + (\sqrt{a} ...

随机推荐

  1. pads怎么高亮网络

    pads怎么高亮网络 选择完整个网络----再按CTRL+H 就高亮了. 取消高亮是,选择需要取消高亮的整个网络,按 CTRL+U 就取消了. PADS在生成Gerber时过孔盖油设置方法 PADS2 ...

  2. java应用:csv文件的读写

    csv数据特点: csv是文本格式,一行数据是一条记录,每个单元之间用“,”隔开.csv数据可以用Excel打开. 读写csv文件的主要程序如下所示: import java.io.BufferedR ...

  3. Python基础教程学记(1)

    引言 Python是什么?——Python是一种面向对象的解释性高级编程语言,具有动态语义.这句话的要点在于,Python是一种知道如何不妨碍你编写程序的编程语言.它让你能够毫无困难地实现所需的功能, ...

  4. Less Is More【少即是多】

    Less Is More Adults understand what it feels like to be flooed with objects. 成年人知道被物品淹没的感觉. Why do w ...

  5. Hive 复杂数据类型的使用

    Hive复杂数据类型 1.Array数据类型的使用 1.1.创建数据库表,以array作为数据类型 hive (hive_demo1)> create table stu_test(name a ...

  6. 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(三):设置上传文件夹权限(这里测试用完全共享)

    基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...

  7. laravel读excel

    fileName = "test.xls";$filePath = "../storage/app/";Excel::load($filePath.$fileN ...

  8. java堆内存模型

     广泛地说,JVM堆内存被分为两部分——年轻代(Young Generation)和老年代(Old Generation). 年轻代 年轻代是所有新对象产生的地方.当年轻代内存空间被用完时,就会触发垃 ...

  9. howto:在构建基于debian的docker基础镜像时,更换国内包源

    debian经常被用作构建应用镜像的基础镜像,如微软在构建linux下的dotnetcore基础镜像时,提供了基于debian 8(jessie)和debian 9(stretch)的镜像. 由于这些 ...

  10. crm踩坑记(一)

    目录 antd es6 Object.entries() Object.keys() Object.getOwnPropertyNames() 很神奇的用法!!! eslint 傻逼 其他 参考 an ...