HDOJ 5671 Matrix

Matrix

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 780    Accepted Submission(s): 330

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 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 

中文题面:BC Round #81 (div.2)1002

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int map[1010][1010];
int row[1010],col[1010];
int hx[1010],hy[1010];
int main()
{
	int t,n,m,q,i,j,a,x,y;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d%d",&n,&m,&q);
		for(i=1;i<=n;++i)
		{
			for(j=1;j<=m;++j)
			{
				scanf("%d",&map[i][j]);
				row[i]=i;
				hx[i]=0;
			}
		}
		for(j=1;j<=m;++j)
		{
			col[j]=j;
			hy[j]=0;
		}
		while(q--)
		{
			scanf("%d%d%d",&a,&x,&y);
			if(a==1)
				swap(row[x],row[y]);
			else if(a==2)
				swap(col[x],col[y]);
			else if(a==3)
				hx[row[x]]+=y;
			else
				hy[col[x]]+=y; 

		}
		for(i=1;i<=n;++i)
		{
			for(j=1;j<=m;++j)
			{
				if(j==m)
					printf("%d\n",map[row[i]][col[j]]+hx[row[i]]+hy[col[j]]);
				else
					printf("%d ",map[row[i]][col[j]]+hx[row[i]]+hy[col[j]]);
			}
		}
	}
	return 0;
} 
时间: 2024-10-16 19:56:07

HDOJ 5671 Matrix的相关文章

hdu 5671 Matrix(BC——思维题)

题目链接:acm.hdu.edu.cn/showproblem.php?pid=5671 Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 891    Accepted Submission(s): 371 Problem Description There is a matrix M that has n rows

HDOJ 3376 Matrix Again

和HDOJ 2686 一样,只是范围不同 最大费用最大流..... 与最小费用最大流的区别用////////////标出来了 对于detour,在源点和汇点处的边的流量为2 对于每个点只能经过一次,拆点,两个点直接建一条流量为1,费用为mp[i][j]的边 对于每个点可以走到他的左边和下边:连一个费用为0流量大于1的边 Matrix Again Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Jav

HDU 5671 Matrix

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 perf

HDU 5671 Matrix (BestCoder Round #81 (div.2) 1002)

传送门 Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 311    Accepted Submission(s): 142 Problem Description There is a matrix M that has n rows and m columns (1≤n≤1000,1≤m≤1000).Then we

hdoj 3376 Matrix Again and hdoj 2686 Matrix 【最大费用最大流】

Matrix Again Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others) Total Submission(s): 3453    Accepted Submission(s): 1017 Problem Description Starvae very like play a number game in the n*n Matrix. A positive intege

HDOJ 233 Matrix 5015【矩阵快速幂】

233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1355    Accepted Submission(s): 806 Problem Description In our daily life we often use 233 to express our feelings. Actually, we may

[Hdoj] Fast Matrix Calculation

题面:http://acm.hdu.edu.cn/showproblem.php?pid=4965 题解:https://www.zybuluo.com/wsndy-xx/note/1153981 原文地址:https://www.cnblogs.com/shandongs1/p/9063619.html

hdoj 3376,2686 Matrix Again 【最小费用最大流】

题目:hdoj 3376 Matrix Again 题意:给出一个m*n的矩阵,然后从左上角到右下角走两次,每次只能向右或者向下,出了末尾点其他只能走一次,不能交叉,每次走到一个格子拿走这个格子中的数字,求价值最大? 分析:很明显费用流,开始想的到一种建图方案,但是那样的话流量全为负值的话会成一个环,所以果断换了. 建图方案是: 首先拆点,每个点拆成两个i 和 ii ,建边,费用为当前格子的值,流量为1,初始点和末尾点为2 然后每个点向它的右边和下边分别建边,容量为1,费用为0 s 连接 左上角

签到 2016.5.10

1.HDU 5670 Machine 解题思路: 变化的规律为红 -> 绿 -> 蓝 -> 红 将红.绿.蓝分别表示0.1.2 原问题就转化为求 n 的三进制表示的最低的 m 位,即求n mod 3^m??的三进制表示 复杂度 O(m) #include <iostream> #include <cstdio> using namespace std; typedef long long LL; const int maxn = 30 + 5; char s[ma