Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟
C. Little Artem and Matrix
题目连接:
http://www.codeforces.com/contest/669/problem/C
Description
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 m from 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 n, m 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 ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ 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.
Sample Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Sample Output
8 2
1 8
Hint
题意
给你一个矩阵,这个矩阵有三个操作
1.将矩阵的第x行向左边旋转一位
2.将矩阵的第y列向上边旋转一位
3.现在的第x,y位置是z
问你最初的矩阵长什么样子
题解:
显然就是倒着去做就好了
仔细一看数据范围,直接暴力莽一波就好了,太小了……
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
int mp[maxn][maxn],q,n,m;
struct node
{
int a,b,c,d;
}Q[maxn*maxn];
void solve1(int x)
{
int tmp = mp[x][m];
for(int i=m;i>=2;i--)
mp[x][i]=mp[x][i-1];
mp[x][1]=tmp;
}
void solve2(int x)
{
int tmp = mp[n][x];
for(int i=n;i>=2;i--)
mp[i][x]=mp[i-1][x];
mp[1][x]=tmp;
}
void solve3(int x,int y,int z)
{
mp[x][y]=z;
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=q;i++)
{
scanf("%d",&Q[i].a);
if(Q[i].a==1)scanf("%d",&Q[i].b);
if(Q[i].a==2)scanf("%d",&Q[i].b);
if(Q[i].a==3)scanf("%d%d%d",&Q[i].b,&Q[i].c,&Q[i].d);
}
for(int i=q;i>=1;i--)
{
if(Q[i].a==1)solve1(Q[i].b);
if(Q[i].a==2)solve2(Q[i].b);
if(Q[i].a==3)solve3(Q[i].b,Q[i].c,Q[i].d);
}
for(int i=1;i<=n;i++,printf("\n"))
for(int j=1;j<=m;j++)
printf("%d ",mp[i][j]);
}
Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟的更多相关文章
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance
题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学
C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组
E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟
D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题
B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题
A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...
- Codeforces Round #348(VK Cup 2016 - Round 2)
A - Little Artem and Presents (div2) 1 2 1 2这样加就可以了 #include <bits/stdc++.h> typedef long long ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D
D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C
C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input s ...
随机推荐
- 蓝色的企业后台cms管理系统——后台
链接:http://pan.baidu.com/s/1kViBtTt 密码:7hbk
- Linux SCIM/fcitx/ibus 输入法
现在很多发行版linux一般都是装好scim scim-tables-zh 重启就行 但有时重启后还是不能调用 可以用如下方法: 添加文件: sudo gedit /etc/X11/xinit/xin ...
- glom模块的使用(二)
上次我们说到golm的简单应用这次我们继续带结构化数据的其他操作进行学习. Literal 用法:class glom.Literal(value) 这个方法的功能主要是添加自定义的键值. 例如: f ...
- 9.Python3标准库--数据压缩与归档
''' 尽管现代计算机系统的存储能力日益增长,但生成数据的增长是永无休止的. 无损(lossless)压缩算法以压缩或解压缩数据花费的时间来换取存储数据所需要的空间,以弥补存储能力的不足. Pytho ...
- HDU 2147 kiki's game(博弈图上找规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2147 题目大意:给你一个n*m的棋盘,初始位置为(1,m),两人轮流操作,每次只能向下,左,左下这三个 ...
- hdu 5468(dfs序+容斥原理)
Puzzled Elena Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 字节对齐&&sizeof
转:http://blog.chinaunix.net/uid-722885-id-124878.html 1. sizeof应用在结构上的情况 请看下面的结构: struct MyStruct { ...
- appium---【Mac】appium-doctor提示WARN:“fbsimctl cannot be found”解决方案
报错提示截图如下: 解决方案: brew tap facebook/fb brew install fbsimctl --HEAD 执行完命令重新运营appium-doctor即可看到成功已安装此包:
- python部分内容存档
笨办法学python. 1 Ec6字符串和文本... 1 ec7. 1 ec8. 1 Ec9. 1 Ec10 转义字符... 1 Ec11提问... 1 raw_input和input的区别... 1 ...
- LoadRunner 函数大全之中文解释
LoadRunner 函数大全之中文解释 // sapgui_table_set_column_selected 模拟用户 // 单击表中的列标题. int sapgui_table_set_colu ...