关闭

CodeForces 668A Little Artem and Matrix

159人阅读 评论(0) 收藏 举报
分类:
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;
}


0
0
查看评论

codeforces 669C Little Artem and Matrix

Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard...
  • qq_32126633
  • qq_32126633
  • 2017-04-25 20:09
  • 142

CodeForces 669E Little Artem and Time Machine(树状数组)

题意:有三个操作     1 x y,在第x秒插入一个y     2 x y,在第x秒移走一个y     3 x y, 问第x秒有多少个y 思路:听说是可持久化Treap...不过好像无脑树状数组也行 #include u...
  • qq_21057881
  • qq_21057881
  • 2016-04-27 16:08
  • 484

CodeForces 669C Little Artem and Matrix(暴力)

题意:给你一个矩阵,这个矩阵有三个操作           1.将矩阵的第x行向左边旋转一位           2.将矩阵的第y列向上边旋转一位       &#...
  • qq_21057881
  • qq_21057881
  • 2016-04-27 16:03
  • 432

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

C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outp...
  • mengxiang000000
  • mengxiang000000
  • 2017-02-07 19:24
  • 145

Codeforces 442C Artem and Array(stack+贪心)

题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数,删除一个数的得分为两边数的最小值,如果左右有一边不存在则算作0分。问最大得分是多少。 解题思路:首先将连续的a,b,c,a > b &am...
  • u011328934
  • u011328934
  • 2014-06-30 09:20
  • 1536

Codeforces 669C Little Artem and Matrix (模拟)

题意对一个矩阵有三种操作 1.第row行循环右移x位 2.第col列循环下移x位 3.告诉你第row行的第col列的数是x。 要求构造出符合操作的原矩阵。思路因为数据很小,直接暴力就可以了,按照操作倒着模拟一遍,有3操作的就填数,没有的就为0。代码#include <stdio.h&g...
  • Dreamon3
  • Dreamon3
  • 2016-04-28 21:34
  • 327

CodeForces 669A Little Artem and Presents

题意:同学有n个糖果,然后每一次可以给人任意个糖果,但是给出去的糖果数量得保证和上一次的数量不一样。问你最多能给多少手 思路:显然是1 2 1 2 1 2这样的... #include using namespace std; int main() { int n; sc...
  • qq_21057881
  • qq_21057881
  • 2016-04-27 16:00
  • 364

CodeForces 668B Little Artem and Dance

Little Artem and Dance
  • Dacc123
  • Dacc123
  • 2016-05-02 13:15
  • 278

CodeForces 669B Little Artem and Grasshopper

题意:有格子是1*n这么大的,每个格子里面都写着一个箭头,表示这个人要往哪儿去跳,并且给你这个人跳跃的距离是多少,然后问你这个人会不会一直跳下去…… 思路:开个数组标记下就可以了 #include using namespace std; const int maxn = 1e6+10;...
  • qq_21057881
  • qq_21057881
  • 2016-04-27 16:02
  • 381

codeforces 669B Little Artem and Grasshopper

点击打开链接 B. Little Artem and Grasshopper time limit per test 2 seconds memory limit per test 256 megabytes input standa...
  • zhang__liuchen
  • zhang__liuchen
  • 2017-08-13 16:07
  • 236
    个人资料
    • 访问:172636次
    • 积分:8463
    • 等级:
    • 排名:第2795名
    • 原创:705篇
    • 转载:2篇
    • 译文:0篇
    • 评论:19条
    最新评论