Matrix

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

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≤M,i,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 4 2
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

 
Recommend
wange2014   
题目大意:有一个n行m列的矩阵,在这个矩阵上进行q个操作,输出经过所有q个操作以后的矩阵M
思路:用4个数组,对于交换行、交换列的操作,分别记录当前状态下每一行、每一列是原始数组的哪一行、哪一列即可。
对每一行、每一列加一个数的操作,也可以两个数组分别记录。
注意当交换行、列的同时,也要交换增量数组。
输出时通过索引找到原矩阵中的值,再加上行、列的增量。
#include <iostream>
#include <string.h>
using namespace std;
int h[],l[], zh[], zl[];
int a[][];
int main()
{
int T, n, m, q, i, j, c, x, y, t;
cin>>T;
while(T--)
{
memset(zh,,sizeof(zh));
memset(zl,,sizeof(zl));
for(i=;i<=;i++)
h[i]=l[i]=i;
scanf("%d%d%d", &n, &m, &q);
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d", &a[i][j]);
while(q--)
{
scanf("%d%d%d", &c, &x, &y);
if(c==) {t=h[x];h[x]=h[y];h[y]=t;}
else if(c==) {t=l[x];l[x]=l[y];l[y]=t;}
else if(c==) zh[h[x]] += y;
else if(c==) zl[l[x]] += y;
}
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
if(j==)
printf("%d", a[h[i]][l[j]]+zh[h[i]]+zl[l[j]]);
else
printf(" %d", a[h[i]][l[j]]+zh[h[i]]+zl[l[j]]);
printf("\n");
}
}
return ;
}
 

HDU 5671 Matrix的更多相关文章

  1. HDU 5671 Matrix 水题

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

  2. hdu 5671 Matrix 标记。。。有点晕

    Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem ...

  3. HDU 4920 Matrix multiplication(bitset)

    HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...

  4. HDU 2686 Matrix 3376 Matrix Again(费用流)

    HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...

  5. hdu 2686 Matrix 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...

  6. hdu 5569 matrix dp

    matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...

  7. hdu 2119 Matrix(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119 Matrix Time Limit: 5000/1000 MS (Java/Others)    ...

  8. HDU - 233 Matrix

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5015 解题思路:一看到题目,感觉是杨辉三角形,然后用组合数学做,不过没想出来怎么做,后来看数据+递推思 ...

  9. HDU——2119 Matrix

    Matrix Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

随机推荐

  1. RobotFramework 安装配置(二)

    前面已经写了一篇关于RF的安装配置了,那是在做自动化工具调研的时候搭建RF总结的,基于win32的系列软件安装的过程.经过1个月的调研,做成了demo,也大致学RF的使用和python的基础语法,暂时 ...

  2. Server2003系统上的内置服务器设置某类IP无法访问问题

    最近测试过程中遇到了一个很奇怪的现象,把服务器(测试产品)部署在Server2003系统的外网A上,把客户端(测试产品)部署在内网B,网络A,B用路由器相连,设置网络A为200.1.1.255,发现客 ...

  3. 【RoR win32】新rails运行后0.0.0.0:3000不能访问

    在浏览器中使用127.0.0.1:3000来访问

  4. ubuntu的目录结构

    /:根目录,一般根目录下只存放目录,不要存放文件,/etc./bin./dev./lib./sbin应该和根目录放置在一个分区中 /bin:/usr/bin:可执行二进制文件的目录,如常用的命令ls. ...

  5. 详解Android AM命令

    1.简介 在Android中,我们除了从界面上启动程序之外,还可以从命令行启动程序,如使用命令行工具am. am全称activity manager,是Android下非常实用命令,其代码在frame ...

  6. win7 chm 打开失败记录

    近期学习rails,制作的html帮助文件想生成chm文件,用了几个网上的html制作chm软件,生成的chm无法打开. 网上大部分解决方法是修改文件属性,Unlock之后可解决. 以前遇到过打不开, ...

  7. InnoDB Status Output – Buffer Pool and Spin Rounds

    InnoDB has a good source of information about its status which can be requested every time you need ...

  8. python logging 替代print 输出内容到控制台和重定向到文件

    转自:http://blog.csdn.net/z_johnny/article/details/50740528

  9. 坑爹的VS2012

    2.2.2.如果卸载 Visual Studio 2010 Service Pack 1,则必须先重新安装 Visual Studio 2010,然后才能再次安装 SP1 如果卸载 Visual St ...

  10. discuz阅读权限的设置作用

    为什么要有阅读权限?偶想很多新手有这个疑问吧,所以特开此帖说明下. 阅读权限的设置是帖子作者为了部分限制帖子的读者群.虽然网上发帖重在分享,但帖子(尤其精华帖子)是作者花时间和经历而写成的,不加阅读权 ...