codeforces 669C C. Little Artem and Matrix(水题)
题目链接:
C. Little Artem and Matrix
2 seconds
256 megabytes
standard input
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 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.
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.
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.
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
8 2
1 8
3 3 2
1 2
3 2 2 5
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+;
const ll inf=1e15;
const int N=1e4+;
int a[][],n,m,q,t[N],y[N],r[N],c[N],x[N];
int main()
{
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<q;i++)
{
scanf("%d",&t[i]);
if(t[i]==)
{
scanf("%d",&y[i]);
}
else if(t[i]==)
{
scanf("%d",&y[i]);
}
else
{
scanf("%d%d%d",&r[i],&c[i],&x[i]);
//a[r][c]=x;
}
}
for(int i=q-;i>=;i--)
{ if(t[i]==)
{
a[r[i]][c[i]]=x[i];
}
else if(t[i]==)
{
int temp=a[y[i]][m];
for(int j=m;j>;j--)
{
a[y[i]][j]=a[y[i]][j-];
}
a[y[i]][]=temp;
}
else
{
int temp=a[n][y[i]];
for(int j=n;j>;j--)
{
a[j][y[i]]=a[j-][y[i]];
}
a[][y[i]]=temp;
}
}
for(int i=;i<=n;i++)
{
for(int j=;j<m;j++)
{
printf("%d ",a[i][j]);
}
printf("%d\n",a[i][m]);
} return ;
}
codeforces 669C C. Little Artem and Matrix(水题)的更多相关文章
- codeforces 669B B. Little Artem and Grasshopper(水题)
		
题目链接: B. Little Artem and Grasshopper time limit per test 2 seconds memory limit per test 256 megaby ...
 - codeforces 669A A. Little Artem and Presents(水题)
		
题目链接: A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes ...
 - codeforces Gym 100187L L. Ministry of Truth 水题
		
L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
 - Codeforces Round #185 (Div. 2) B. Archer 水题
		
B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...
 - Educational Codeforces Round 14 A. Fashion in Berland 水题
		
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
 - Codeforces Round #360 (Div. 2) A. Opponents 水题
		
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
 - Codeforces Round #190 (Div. 2) 水果俩水题
		
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
 - Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告
		
对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...
 - 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 ...
 
随机推荐
- python中单引号,双引号,三引号的比较  转载
			
本文转载自http://blog.sina.com.cn/s/blog_6be8928401017lwy.html 先说1双引号与3个双引号的区别,双引号所表示的字 符串通常要写成一行 如: s1 = ...
 - 使用EventNext实现基于事件驱动的业务处理
			
事件驱动模型相信对大家来说并不陌生,因为这是一套非常高效的逻辑处理模型,通过事件来驱动接下来需要完成的工作,而不像传统同步模型等待任务完成后再继续!虽然事件驱动有着这样的好处,但在传统设计上基于消息回 ...
 - 梯度下降和EM算法,kmeans的em推导
			
I. 牛顿迭代法给定一个复杂的非线性函数f(x),希望求它的最小值,我们一般可以这样做,假定它足够光滑,那么它的最小值也就是它的极小值点,满足f′(x0)=0,然后可以转化为求方程f′(x)=0的根了 ...
 - Android 系统广播机制
			
一.Android应用程序注冊广播接收器(registerReceiver)的过程分析 參考Android应用程序注冊广播接收器(registerReceiver)的过程分析http://blog.c ...
 - takeLatest 如何接受 this.props.dispatch 传递的参数
			
1.步骤一 // 获取查询参数 getQueryParams(params){ // 请求月考核分的数据 this.props.dispatch({ type:'getMonthlyAssessmen ...
 - PHP中的多行字符串传递给JavaScript方法两则
			
PHP和JavaScript都是初学.近期有这么个需求: 例如说有一个PHP的多行字符串: $a = <<<EOF thy38 csdn blog EOF; 传递给JavaScrip ...
 - AJAX核心XMLHTTPRequest对象
			
老早就写好了总结.今天整理发表一下. XMLHttpRequest对象是AJAX的核心技术,XMLHttpRequest 是XMLHTTP 组件的对象,通过这个对象.AJAX能够像桌面应用程序一样仅仅 ...
 - Qt、C++ 简易计算器
			
Qt.C++实现简易计算器: 以下内容是我实现这个简易计算器整个过程,其中包括我对如何实现这个功能的思考.中途遇到的问题.走过的弯路 整个实现从易到难,计算器功能从简单到复杂,最开始设计的整个实现步骤 ...
 - 模式识别之聚类算法k-均值---k-均值聚类算法c实现
			
//写个简单的先练习一下,测试通过 //k-均值聚类算法C语言版 #include <stdlib.h> #include <stdio.h> #inc ...
 - linux学习:进程间通信—管道
			
1.进程间通信当中一种比較简单的方法是管道操作 /* ========================================================================= ...