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入门学习笔记4:他人的博客及他人的学习思路

    看其他人的学习笔记,可以保证自己不走弯路.并且一举两得,即学知识又学方法! 廖雪峰:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958 ...

  2. Java集合类面试题

    java.util包中包含了一系列重要的集合类,而对于集合类,主要需要掌握的就是它的内部结构,以及遍历集合的迭代模式. 1.Java集合框架是什么?说出一些集合框架的优点? 每种编程语言中都有集合,最 ...

  3. 网易云terraform实践

    此文已由作者王慎为授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 一.terraform介绍 随着应用上云的常态化,资源栈动态管理的需求对用户也变得更加急切.资源编排(Res ...

  4. 破解PHPStrom 10 and Pycharm

    注册时选择 License server http://idea.lanyus.com/ 然后点击OK Pycharm -- License server http://idea.lanyus.com ...

  5. github简单使用教程(转)

    github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要公开.对于一般人来说公共仓库就已经足够了,而且我们也没多少代码来管理,O(∩_∩)O ...

  6. 在Android上Kotlin的单元测试(KAD22)

    作者:Antonio Leiva 时间:Apr 25, 2017 原文链接:https://antonioleiva.com/unit-tests-android-kotlin/ 当然,Kotlin也 ...

  7. jmeter如何连接数据库

    大家都知道jmeter是java编写的,java/jmeter如果想连接数据库就要通过java database connector(JDBC)去连接,首先需先下载一个驱动 (mysql-connec ...

  8. 接口自动化测试框架Karate入门

    介绍 在这篇文章中,我们将介绍一下开源的Web-API自动化测试框架--Karate Karate是基于另一个BDD测试框架Cucumber来建立的,并且共用了一些相同的思想.其中之一就是使用Gher ...

  9. P5056 插头dp

    题面 Source: unordered_map: #include <iostream> #include <tr1/unordered_map> #include < ...

  10. UVA 11880 Ball in a Rectangle(数学+平面几何)

    Input: Standard Input Output: Standard Output � There is a rectangle on the cartesian plane, with bo ...