Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C
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 题意:恶心模拟 3种对矩阵的操作
1 r 第r行的第一个元素放到最后一个
2 c 第c列的第一个元素放到最后一个
3 r c x 第r行c列的赋值为x
给你q个操作 输出初始矩阵 题解:恶心倒序模拟
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define ll __int64
#define pi acos(-1.0)
#define mod 1
#define maxn 10000
using namespace std;
int n,m,q;
struct node
{
int type;
int r,l,value;
}N[];
int mp[][];
int exm;
int main()
{
scanf("%d %d %d",&n,&m,&q);
memset(mp,,sizeof(mp));
memset(N,,sizeof(N));
for(int i=;i<=q;i++)
{
scanf("%d",&exm);
N[i].type=exm;
if(exm==)
scanf("%d",&N[i].r);
if(exm==)
scanf("%d",&N[i].l);
if(exm==)
scanf("%d %d %d",&N[i].r,&N[i].l,&N[i].value);
}
for(int i=q;i>=;i--)
{
if(N[i].type==)
{
int gg=mp[N[i].r][m];
for(int j=m-;j>=;j--)
mp[N[i].r][j+]=mp[N[i].r][j];
mp[N[i].r][]=gg;
}
if(N[i].type==)
{
int gg=mp[n][N[i].l];
for(int j=n-;j>=;j--)
mp[j+][N[i].l]=mp[j][N[i].l];
mp[][N[i].l]=gg;
}
if(N[i].type==)
{
mp[N[i].r][N[i].l]=N[i].value;
}
}
for(int i=;i<=n;i++)
{
cout<<mp[i][];
for(int j=;j<=m;j++)
cout<<" "<<mp[i][j];
cout<<endl;
}
return ;
}
Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C的更多相关文章
- 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) C. Little Artem and Matrix 模拟
C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...
- 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 ...
随机推荐
- python学习之路2(程序的控制结构)
1.程序的分支结构 1.1 单分支 if <条件>: 例:guess = eval(input()) <语句块> ...
- Typora -- 书写即美学
#Typora -- 书写即美学 ##基本快捷键--需要在所见即所想界面进行输入 加粗 Ctrl + B 加粗 斜体 Ctrl + I 斜体 下划线 Ctrl + U 下划线 删除线 Ctrl + S ...
- WHERE条件中or与union引起的全表扫描的问题
说起数据库的SQL语句执行效率的问题,就不得不提where条件语句中的or(逻辑或)引起的全表扫描问题,从而导致效率下降. 在以往绝大多数的资料中,大多数人的建议是使用 union 代替 or ,以解 ...
- http一些常见知识记录
HTTP请求包(浏览器信息) 我们先来看看Request包的结构, Request包分为3部分,第一部分叫Request line(请求行), 第二部分叫Request header(请求头),第三部 ...
- Go语言获取本地IP地址
最近要做一个向局域网内的所有设备广播发送信息,并接受设备的回复信息,回复信息包括设备的版本号,IP地址,运行工程名等信息.发现一个局域网内是可以有不同的网段的,但UDP广播只能是同一个网段的广播.又发 ...
- MVC5使用单选按钮与下拉框【转】
某人认为下拉列表的呈现形式不如单选按钮漂亮,我只好去测试一下单选按钮与下拉框了.测试代码如下: 1.model类Blog.cs(类型使用枚举类型,自动生成的视图会以下拉列表形式显示): using S ...
- 用链表实现nodejs的内存对象管理
虽然javascript拥有垃圾收集,但是垃圾收集机制并不会自动释放持久对象,比如websocks连接. 为了能够在某些特定情况下中止一些连接(比如内存不足),显然要建立全局的对象管理器进行管理. 显 ...
- K8s集群内热改代码
1.登录到k8s master服务器 $ ssh developer@XXX.XXX.X.XXX(IP地址) 2.查看服务容器所在的节点(以xx-server为例) $ kubectl get pod ...
- flask中static_folder与static_url_path的区别与联系
# -*- coding:utf-8 -*- from flask import Flask, url_for app1 = Flask(__name__, static_folder='mystat ...
- mysql语法总结
增: 删: 改: 查: 索引: 建: alter table: sql一些常用的经典语句,最后是select as的用法