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个数组,对于交换行、交换列的操作,分别记录当前状态下每一行、每一列是原始数组的哪一行、哪一列即可。
对每一行、每一列加一个数的操作,也可以两个数组分别记录。
注意当交换行、列的同时,也要交换增量数组。
输出时通过索引找到原矩阵中的值,再加上行、列的增量。
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. int h[],l[], zh[], zl[];
  5. int a[][];
  6. int main()
  7. {
  8. int T, n, m, q, i, j, c, x, y, t;
  9. cin>>T;
  10. while(T--)
  11. {
  12. memset(zh,,sizeof(zh));
  13. memset(zl,,sizeof(zl));
  14. for(i=;i<=;i++)
  15. h[i]=l[i]=i;
  16. scanf("%d%d%d", &n, &m, &q);
  17. for(i=;i<=n;i++)
  18. for(j=;j<=m;j++)
  19. scanf("%d", &a[i][j]);
  20. while(q--)
  21. {
  22. scanf("%d%d%d", &c, &x, &y);
  23. if(c==) {t=h[x];h[x]=h[y];h[y]=t;}
  24. else if(c==) {t=l[x];l[x]=l[y];l[y]=t;}
  25. else if(c==) zh[h[x]] += y;
  26. else if(c==) zl[l[x]] += y;
  27. }
  28. for(i=;i<=n;i++)
  29. {
  30. for(j=;j<=m;j++)
  31. if(j==)
  32. printf("%d", a[h[i]][l[j]]+zh[h[i]]+zl[l[j]]);
  33. else
  34. printf(" %d", a[h[i]][l[j]]+zh[h[i]]+zl[l[j]]);
  35. printf("\n");
  36. }
  37. }
  38. return ;
  39. }
 

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. 供应商 银行 SQL (转自ITPUB)

    在此记录一下自己学习过程.新手,请多多指教,谢谢. 最近客户有需求,找出供应商对应的银行信息,查看了下网上帖子,发现都是从供应商及供应商地点层发起,去查找对应的银行信息,但是,供应商维护银行界面共有四 ...

  2. 夺命雷公狗---Thinkphp----4之数据表的设计

    我们这次来写的项目是仿http://yispace.net/39765.html而写的, 这里其实也就那回事,主要有标题和内容,和栏目, 文章页就更加的简单,其实也就那及格字段即可,我们分享得出的结果 ...

  3. yii2多语言设置

    yii2的多语言切换功能 1.页面添加语言切换按钮,如下图: 代码如下: <ul>       <li>           <a href="javascri ...

  4. T-sql语句中GO的作用及语法【转】

    1. 作用: 向 SQL Server 实用工具发出一批 Transact-SQL 语句结束的信号.2. 语法:一批 Transact-SQL 语句GO如Select 1Select 2Select ...

  5. Android压力测试快速入门教程(图解)——Monkey工具

    文章目录: 一.Monkey简介 二.Monkey的基本用法 三.Monkey测试示例图解 四.Monkey命令参数介绍 五.Monkey log分析 一.Monkey简介 Monkey:Androi ...

  6. 《Linux命令行与shell脚本编程大全》 第二十三章 学习笔记

    第二十三章:使用数据库 MySQL数据库 MySQL客户端界面 mysql命令行参数 参数 描述 -A 禁用自动重新生成哈希表 -b 禁用 出错后的beep声 -B 不使用历史文件 -C 压缩客户端和 ...

  7. redmine plugin

    http://wangsheng2008love.blog.163.com/blog/static/78201689200992064615770/

  8. java运算符优先级记忆口诀

    尊重原创:(口诀)转自http://lasombra.iteye.com/blog/991662 今天看到<java编程思想>中的运算符优先级助记口诀,不过"Ulcer Addi ...

  9. powershell: 生成随机字符串

    ASCII范围内的 获取6个随机字符(字母和数字) 48到57是数字0-9,powershell的范围操作符是..,和Perl 5的一样, 所以 48..57就是指(48 49 50 51 52 53 ...

  10. javaWeb 使用cookie显示上次访问网站时间

    package de.bvb.cookie; import java.io.IOException; import java.io.PrintWriter; import java.util.Date ...