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. python字符串编码

    python默认编码 python 2.x默认的字符编码是ASCII,默认的文件编码也是ASCII. python 3.x默认的字符编码是unicode,默认的文件编码是utf-8. 中文乱码问题 无 ...

  2. PAT-B java实现

    注意:java提交PAT时,不需要加package : 类名必须是Main. 1001 害死人不偿命的(3n+1)猜想 (15) 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值. 输出格式 ...

  3. rhel6.4扩充swap分区

    状况:Red hat 6.4 swap分区不足 解决:扩充swap ================================================================== ...

  4. Element-ui学习使用

    这是我使用Element-ui的布局,排布的一个界面,原本我是使用WinfowsForm来做的一个摄像头注册以及查询的小工具,目前我关注前后端的开发,所以就想着能不能把这么个小工具,我用前后端的形式开 ...

  5. matlab-罗曼诺夫斯基准则剔除粗大值

    罗曼诺夫斯基准则原理  罗曼诺夫斯基准则又称 t检验准则,其特点是首先删除一个可疑的的测得值,然后按 t分布检验被剔除的测量值是否含有粗大误差 罗曼诺夫斯基准则  1)选取合适的显著度a,选择合适的数 ...

  6. 汇编实验15:安装新的int 9中断例程

    汇编实验15:安装新的int 9中断例程 任务 安装一个新的int 9中断例程,功能:在DOS下,按下“A”键后,除非不在松开,一旦松开后,就显示满屏幕的“A”,其他键照常处理. 预备知识概要 这次实 ...

  7. WPF中使用定时器的注意事项

    原文:WPF中使用定时器的注意事项 注意事项 要使用System.Windows.Threading.DispatcherTimer,而不能使用System.Timers.Timer. 原因是WPF是 ...

  8. django 解决cors问题

    首页 博客 学院 下载 GitChat TinyMind 论坛 问答 商城 VIP 活动 招聘 ITeye CSTO 写博客 发Chat 登录注册 AFei0018-博客 穷则思变,差则思勤.Pyth ...

  9. 简单工具 & 杂技

    图片压缩: 腾讯智图(http://zhitu.isux.us/) 手机的所有尺寸大小规范: http://screensiz.es/phone 需求: 移动端宽高一致的盒子(因为移动端屏幕宽度不一样 ...

  10. 讨伐Cucumber行为驱动

    Cucumber行为驱动,简称BDD,其核心思想是把自然语言转换成代码:但在敏捷开发的过程中,这种东西极大的束缚了测试人员的手脚,感觉它像封建时代的八股文,要遵守严格的韵律,反正我个人十分反感:就像在 ...