hdoj5671 BestCoder Round #81 (div.2)
对于交换行、交换列的操作,分别记录当前状态下每一行、每一列是原始数组的哪一行、哪一列即可。
对每一行、每一列加一个数的操作,也可以两个数组分别记录。注意当交换行、列的同时,也要交换增量数组。
输出时通过索引找到原矩阵中的值,再加上行、列的增量。
复杂度O(q+mn)
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#include<queue>
#include<stdlib.h>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
using namespace std;
#define INF 0x3f3f3f3f
#define N 1010
int a[N][N];
int ans[N][N];
int xh[N],h[N];
int xl[N],l[N];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int q,n,m;
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
}
memset(xh,0,sizeof(xh));
memset(xl,0,sizeof(xl));
for(int i=1;i<=n;i++)
h[i]=i;
for(int i=1;i<=m;i++)
l[i]=i;
int k,x,y;
for(int i=0;i<q;i++)
{
scanf("%d%d%d",&k,&x,&y);
if(k==1)
{
int t=h[x];
h[x]=h[y];
h[y]=t;
}
else if(k==2)
{
int t=l[x];
l[x]=l[y];
l[y]=t;
}
else if(k==3)
{
xh[h[x]]+=y;
}
else if(k==4)
{
xl[l[x]]+=y;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
ans[i][j]=a[h[i]][l[j]]+xh[h[i]]+xl[l[j]];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(j!=1)
printf(" ");
printf("%d",ans[i][j]);
}
printf("\n");
}
}
return 0;
}
hdoj5671 BestCoder Round #81 (div.2)的更多相关文章
- BestCoder Round #81 (div.2) 1004 String(动态规划)
题目链接:BestCoder Round #81 (div.2) 1003 String 题意 中文题,上有链接.就不贴了. 思路 枚举起点i,计算能够达到k个不同字母的最小下标j,则此时有子串len ...
- BestCoder Round #81 (div.2) 1003 String
题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=691&pid=1003题意:找出一个字符串满足至少 ...
- BestCoder Round #81 (div.2)C String
总体思路好想,就是在找K个不同字母的时候,卡时间. 看了大神代码,发现goto的!!!!998ms #include<cstdio> #include<cstring> #in ...
- BestCoder Round #81 (div.2) B Matrix
B题...水题,记录当前行是由原矩阵哪行变来的. #include<cstdio> #include<cstring> #include<cstdlib> #inc ...
- BestCoder Round #81 (div.1)A
水题...就是n的三进制后m位 #include<cstdio> #include<cstring> #include<cstdlib> #include<i ...
- BestCoder Round #81 (div.2)1001
Machine Accepts: 580 Submissions: 1890 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65 ...
- BestCoder Round #81 (div.2)
HDU:5670~5764 A题: 是一个3进制计数: #include <bits/stdc++.h> using namespace std; ]; int calc(long lon ...
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- BestCoder Round #68 (div.2) tree(hdu 5606)
tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
随机推荐
- JavaSE Map的使用
1.Map概述 Map与Collection并列存在.用来保存具有映射关系的数据:Key-Value Map 中的 key 和 value都能够是不论什么引用类型的数据 Map 中的 key 用Se ...
- XSS学习分支图
转载请注明出处:http://blog.csdn.net/cym492224103 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2 ...
- SQL SELECT TOP, LIMIT, ROWNUM 子句
SQL SELECT TOP, LIMIT, ROWNUM 子句 SQL SELECT TOP 子句 SELECT TOP 子句用于规定要返回的记录的数目. SELECT TOP 子句对于拥有数千条记 ...
- Vue 开发线路 资料 汇总
线路 作者推荐学习线路 https://zhuanlan.zhihu.com/p/23134551 他人建议 https://www.cnblogs.com/smartXiang/p/6051086. ...
- C#语言 数组
- 全文索引--自己定义chinese_lexer词典
本文来具体解释一下怎样自己定义chinese_lexer此法分析器的词典 初始化数据 create table test2 (str1 varchar2(2000),str2varchar2(2000 ...
- 自己动手写CPU之第九阶段(7)——MIPS32中的LL、SC指令说明
将陆续上传新书<自己动手写CPU>,今天是第46篇. 在MIPS32指令集中有两条特殊的存储载入指令:链接载入指令LL.条件存储指令SC,本次将介绍这两条指令.在兴许将实现这两条指令. 9 ...
- (testng多个class文件执行时混乱,不是等一个class内的所有methods执行完再去执行下一个class内的内容)问题的解决
问题描述如下: We use TestNG and Selenium WebDriver to test our web application. Now our problem is that we ...
- MongoDB经常使用命令
首先我们先安装这个数据库.你能够使用windows或者linux,但推荐使用的是linux,我使用的是ubuntu12.04.在下方的网址中共能够下载,基本都是64位的系统. 假设位linux系统也能 ...
- c语言基本函数
1. 用宏定义写出swap(x,y) #define swap(x, y) x = x + y; y = x - y; x = x - y; 2.数组a[N],存放了1至N-1个数,其中某个数重复一次 ...