CodeForces 669C Little Artem and Matrix(暴力)
2016-04-27 16:03
375 查看
题意:给你一个矩阵,这个矩阵有三个操作
1.将矩阵的第x行向左边旋转一位
2.将矩阵的第y列向上边旋转一位
3.现在的第x,y位置是z
问你最初的矩阵长什么样子
思路:显然倒着做然后暴力就好了
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
Input
Output
Input
Output
1.将矩阵的第x行向左边旋转一位
2.将矩阵的第y列向上边旋转一位
3.现在的第x,y位置是z
问你最初的矩阵长什么样子
思路:显然倒着做然后暴力就好了
#include<bits/stdc++.h> using namespace std; const int maxn = 105; int mp[maxn][maxn]; int n,m,k; struct Node { int a,b,c,d; }q[maxn*maxn]; void solve1(int x) { int temp = mp[x][m]; for (int i = m;i>=2;i--) mp[x][i] = mp[x][i-1]; mp[x][1]=temp; } void solve2(int x) { int temp = mp [x]; for (int i = n;i>=2;i--) mp[i][x] = mp[i-1][x]; mp[1][x]=temp; } void solve3(int x,int y,int z) { mp[x][y]=z; } int main() { scanf("%d%d%d",&n,&m,&k); for (int i = 1;i<=k;i++) { scanf("%d",&q[i].a); if (q[i].a==1 || 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 = k;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++) { for (int j = 1;j<=m;j++) printf("%d ",mp[i][j]); printf("\n"); } }
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
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
相关文章推荐
- ZOJ3939 The Lucky Week
- 用正则表达式验证邮箱和手机号
- sqlserver 求百分比
- (二)C# winform C/S WebBrowser qq第三方授权登录
- factor graph model
- Spring IOC学习计划
- 自己学习smarty的一些代码 和记录
- 10倍以上提高Pentaho Kettle的MySQL写入速度
- hibernate sqlQuery mysql别名问题
- NYOJ-110-剑客决斗
- Sublime Text3插件安装
- CodeForces 669B Little Artem and Grasshopper
- 第一次使用Android Studio时你应该知道的一切配置
- jQuery上传图片前预览
- 区分:position属性的absolute与relative
- VMware 6.5 下安装 Fedora 9
- 以管理员身份启动ClickOnce部署的应用程序
- IONIC跨域问题
- 使用ShareSDK完成第三方(QQ、微信、微博)登录和分享
- Handler post 和 sendmessage的解析