CodeForces 668A Little Artem and Matrix

原创 2016年06月01日 21:07:22
A. Little Artem and Matrix
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.

That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to mfrom left to right.

Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.

Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.

Input

The first line of the input contains three integers nm and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.

Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers rici and xi (1 ≤ ri ≤ n1 ≤ ci ≤ m - 109 ≤ xi ≤ 109) are given.

Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.

Output

Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.

If there are multiple valid solutions, output any of them.

Examples
input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
output
8 2 
1 8 
input
3 3 2
1 2
3 2 2 5
output
0 0 0 
0 0 5 
0 0 0 
吐槽一下,题目真长,好难理解。。。。。
题意:对一个n*m矩阵进行操作
操作1:将r行的最后一个元素放到第一个,第二个放到第三个,依次向后推。。
操作2:将c列的最后一个元素放到第一个,第二个放到第三个,依次向后。。
操作3: 将r行c列的元素赋值为X;
思路:按照操作进行一遍,不过要进行赋值操作,再进行转换。。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct note
{
	int temp;
	int r,c,val;
}t[110000];
int map[1100][1100];
int main()
{
	int n,m,p,a,i,j;
	while(scanf("%d%d%d",&n,&m,&p)!=EOF)
	{
		memset(map,0,sizeof(map));
		for(i=1;i<=p;i++)
		{
			scanf("%d",&a);
			t[i].temp=a;
			if(a==1)
		    {
		    	scanf("%d",&t[i].r);
			}
			if(a==2)
			{
				scanf("%d",&t[i].c);
			}
			if(a==3)
			{
				scanf("%d%d%d",&t[i].r,&t[i].c,&t[i].val);
			}
		}
		for(i=p;i>=1;i--)
		{
			if(t[i].temp==3)
			map[t[i].r][t[i].c]=t[i].val;
			if(t[i].temp==2)
			{
				int ans=map[n][t[i].c];
				for(j=n-1;j>=1;j--)
				map[j+1][t[i].c]=map[j][t[i].c];
				map[1][t[i].c]=ans;
			}
			if(t[i].temp==1)
			{
				int ans=map[t[i].r][m];
				for(j=m-1;j>=1;j--)
				map[t[i].r][j+1]=map[t[i].r][j];
				map[t[i].r][1]=ans;
			}
		}
		for(i=1;i<=n;i++)
		{
			for(j=1;j<m;j++)
			{
				printf("%d ",map[i][j]);
			}
			printf("%d\n",map[i][j]);
		}
	}
	return 0;
}


版权声明:本文为博主原创文章,转载请注明出处。 举报

相关文章推荐

codeforces 669C Little Artem and Matrix

Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabyte...

Codeforces 669C Little Artem and Matrix (模拟)

题意对一个矩阵有三种操作 1.第row行循环右移x位 2.第col列循环下移x位 3.告诉你第row行的第col列的数是x。 要求构造出符合操作的原矩阵。思路因为数据很小,直接暴力就可以了,按...

精选:深入理解 Docker 内部原理及网络配置

网络绝对是任何系统的核心,对于容器而言也是如此。Docker 作为目前最火的轻量级容器技术,有很多令人称道的功能,如 Docker 的镜像管理。然而,Docker的网络一直以来都比较薄弱,所以我们有必要深入了解Docker的网络知识,以满足更高的网络需求。

Codeforces #669 Div2 C. Little Artem and Matrix(模拟)

题目链接: Codeforces #669 Div2 C. Little Artem and Matrix 题意: 有一个n*m矩阵初始元素值都未知。有三种操作: 1 x 将第x行元素都左移一...

Codeforces 669C Little Artem and Matrix【思维+暴力】

C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes...

CodeForces 668B Little Artem and Dance

Little Artem and Dance

CF Round #348 Div. 2 A. Little Artem and Present B. Little Artem and Grasshopper C. Little Artem and

今天起开始刷CF,不知道能坚持多久,希望不要放弃,编程这东西一放就忘。 关于解题,能用语言描述的东西就不画图了,下面进入正题。 A. Little Artem and Present 题意: 小A...

Codeforces #669 Div2. D. Little Artem and Dance(思维)

题目链接: Codeforces #669 Div2. D. Little Artem and Dance 题意: 初始有n对男生和女生,编号都是从1–n,并且1号男生和1号女生配对,2号男生和...

CodeForces - 668B Little Artem and Dance(规律题)

Little Artem and DanceLittle Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban ...

CodeForces - 668B Little Artem and Dance(模拟,思路)

题目: B. Little Artem and Dance time limit per test 2 seconds memory limit p...

Codeforces 669D Little Artem and Dance (脑洞)

题意给出一个1到n的序列,对他有两个操作: 1.整体向右移动x格子 2.奇偶位的数字互换 求经过q次操作之后的数字序列。思路显然这题是要O(q)来做的,从第一组样例能发现虽然整体在变,但是相邻的...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)