codeforces 669C C. Little Artem and Matrix(水题)
2016-04-25 13:40
323 查看
题目链接:C. Little Artem and Matrixtime limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputLittle 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.InputThe 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.OutputPrint 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.Examplesinput
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputLittle 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.InputThe 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.OutputPrint 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.Examplesinput
2 2 6 2 1 2 2 3 1 1 1 3 2 2 2 3 1 2 8 3 2 1 8output
8 2 1 8input
3 3 2 1 2 3 2 2 5output
0 0 0 0 0 5 0 0 0 题意: 一个n*m的矩阵,有三种操作,一种是循环左移,一种是循环上移,还有就是当前时刻在特定的位置的值是给的数; 要求输出一个符合要求的矩阵; 思路: 把操作的顺序倒过来搞一波,同时的循环移动的方向反过来,检查是否为这个值变成将这个位置的值变为给的值; AC代码:
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod=1e9+7; const ll inf=1e15; const int N=1e4+6; int a[102][102],n,m,q,t ,y ,r ,c ,x ; int main() { scanf("%d%d%d",&n,&m,&q); for(int i=0;i<q;i++) { scanf("%d",&t[i]); if(t[i]==1) { scanf("%d",&y[i]); } else if(t[i]==2) { scanf("%d",&y[i]); } else { scanf("%d%d%d",&r[i],&c[i],&x[i]); //a[r][c]=x; } } for(int i=q-1;i>=0;i--) { if(t[i]==3) { a[r[i]][c[i]]=x[i]; } else if(t[i]==1) { int temp=a[y[i]][m]; for(int j=m;j>1;j--) { a[y[i]][j]=a[y[i]][j-1]; } a[y[i]][1]=temp; } else { int temp=a [y[i]]; for(int j=n;j>1;j--) { a[j][y[i]]=a[j-1][y[i]]; } a[1][y[i]]=temp; } } for(int i=1;i<=n;i++) { for(int j=1;j<m;j++) { printf("%d ",a[i][j]); } printf("%d\n",a[i][m]); } return 0; }
相关文章推荐
- js中的hasOwnProperty和isPrototypeOf方法
- 按钮的设计
- 并查集/图的划分
- android 拨打电话与发送短信
- 什么是大数据概念
- robotframework笔记23
- Python format格式化输出
- 用RAII技术管理资源及其泛型实现
- websocket上传参数中文乱码问题解决
- Hbase 安装配置实验
- 强大的Core Image框架,各种滤镜处理图像
- 从MySQL官方Yum仓库安装MySQL5.6
- 企业集群平台LVS负载均衡算法分析与实现
- 企业集群平台LVS负载均衡算法分析与实现
- iOS巅峰之label描边
- 剑指offer(13):打印1到最大的n位数
- php 如何使用LigerUI grid插件
- Spark Streaming和Kafka整合开发指南(二)
- UIBezierPath画圆弧的记录
- Hadoop点滴