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. MVC4 下DropDownList使用方法

    与MVC3相比,差别很大: 表现形式一: public ActionResult Main() { List<SelectListItem> items = new List<Sel ...

  2. UIViewController卸载过程(ios6.0以后)

    在ios6.0以后,废除了viewWillUnload方法和viewDidUnload方法. 在ios6以后,当收到didReceiveMemoryWarning消息调用之后,程序会自动调用didRe ...

  3. UIViewController卸载过程(ios6.0之前)

    1.当应用程序收到内存不足的警告之后,程序中所有存在的UIViewController都会收到didReceiveMemoryWarning调用消息,目的是将当前不显示的View释放掉,缓解内存压力. ...

  4. 视频处理控件TVideoGrabber视频捕捉设设备相关问题

    选择一个视频捕捉设备 首先设置 VideoSource = vs_VideoCaptureDevice来选择一个视频捕捉设备作为一个视频源. 通过指定VideoDevice属性来选择当前的视频捕捉设备 ...

  5. umask setuid setgid

    cat /etc/bashrc if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ];#用户UI ...

  6. python随机数的使用记录

    一.random模块简介 Python标准库中的random函数,可以生成随机浮点数.整数.字符串,甚至帮助你随机选择列表序列中的一个元素,打乱一组数据等. 二.random模块重要函数 1 ).ra ...

  7. 在路由器 RT-AC68U 使用自定义 DDNS 用 3322.org 动态域名的方法

    0.使用华硕的第三方固件 -- 梅林固件 , 具体更新固件方法不在本主题述说 1.打开 jffs, 以便启动时可以自动执行脚本 2.在 /jffs/scripts 下新建 ddns-start 文件. ...

  8. Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性

    Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性 Apache hadoop 项目组最新消息,hadoop3.x以后将会调整方案架构,将Mapreduce 基于内存+io+ ...

  9. Hibernate,JPA注解@DynamicInsert和@DynamicUpdate,Hibernate如何插入sysdate

    @DynamicInsert属性:设置为true,设置为true,表示insert对象的时候,生成动态的insert语句,如果这个字段的值是null就不会加入到insert语句当中.默认false. ...

  10. 微信公众平台自定义菜单PHP开发

    微信公众平台自定义菜单PHP开发,微信公众平台自定义菜单是如何实现的呢?其实很简单,首先在微信公众平台升级为服务号,获取appid和appsecret,然后根据这2个参数获取access_token, ...