HDU 5671 矩阵
Matrix
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 271 Accepted Submission(s): 126
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)
;
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
.
after all q
operations.
2
Recommand to use scanf and printf
对于交换行、交换列的操作,分别记录当前状态下每一行、每一列是原始数组的哪一行、哪一列即可。
对每一行、每一列加一个数的操作,也可以两个数组分别记录。注意当交换行、列的同时,也要交换增量数组。
输出时通过索引找到原矩阵中的值,再加上行、列的增量
#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 ;
}
最新文章
- jquery的全选插件
- C#之方法的重载与递归
- 【Win10 UWP】后台任务与动态磁贴
- NET基础(2):类型转换
- 第一个python程序hello.py
- asp存储过程
- WF学习
- PHP学习笔记二十四【Get Set】
- Div 滚动栏滚动到指定的位置
- select into from 和 insert into select 的用法
- android BLE Peripheral 模拟 ibeacon 发出ble 广播
- pdf生成库-libharu编译
- JSP:getOutputStream() has already been called for this response
- MT【255】伸缩变换
- ThinkPHP5基础学习(慕课版)
- [laravel]malformed header from script &#39;index.php&#39;: Bad header: HTTP/1.1 302 Found, referer: http://localhost/auth/login
- Lucene实战之基于StandardAnalyzer读写索引
- Docker容器学习梳理 - 容器硬盘热扩容
- Codeforces 260B - Ancient Prophesy
- 【微信小程序推广营销】教你微信小程序SEO优化,让你的小程序快人一步抢占先机
热门文章
- WordPress4.9 最新版本网站安全漏洞详情与修复
- centos 安装java1.8
- 分享一个工作中遇得到的sql(按每天每人统计拖车次数与小修次数)
- 50-Identity MVC:DbContextSeed初始化
- Android Studio modify language level to Java 8
- 3155: Preprefix sum
- 深度学习:激活函数的比较和优缺点,sigmoid,tanh,relu
- Java工程师笔试题整理[校招篇]
- python保留关键字和常用关键字
- 「日常训练」「小专题·图论」 Frogger (1-1)