zoukankan      html  css  js  c++  java
  • 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
    standard input
    output
    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.

    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.

    Examples
    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

    题意:恶心模拟 3种对矩阵的操作
    1 r 第r行的第一个元素放到最后一个
    2 c 第c列的第一个元素放到最后一个
    3 r c x 第r行c列的赋值为x
    给你q个操作 输出初始矩阵

    题解:恶心倒序模拟

     1 #include<iostream>
     2  #include<cstring>
     3  #include<cstdio>
     4  #include<queue>
     5  #include<stack>
     6  #include<map>
     7  #include<set>
     8  #include<algorithm>
     9  #define ll __int64
    10  #define pi acos(-1.0)
    11  #define mod 1
    12  #define maxn 10000
    13  using namespace std;
    14  int n,m,q;
    15  struct node
    16  {
    17      int type;
    18      int r,l,value;
    19  }N[10005];
    20  int mp[105][105];
    21  int exm;
    22  int main()
    23  {
    24      scanf("%d %d %d",&n,&m,&q);
    25      memset(mp,0,sizeof(mp));
    26      memset(N,0,sizeof(N));
    27      for(int i=1;i<=q;i++)
    28      {
    29        scanf("%d",&exm);
    30        N[i].type=exm;
    31        if(exm==1)
    32           scanf("%d",&N[i].r);
    33        if(exm==2)
    34          scanf("%d",&N[i].l);
    35        if(exm==3)
    36         scanf("%d %d %d",&N[i].r,&N[i].l,&N[i].value);
    37      }
    38       for(int i=q;i>=1;i--)
    39       {
    40           if(N[i].type==1)
    41           {
    42               int gg=mp[N[i].r][m];
    43              for(int j=m-1;j>=1;j--)
    44                mp[N[i].r][j+1]=mp[N[i].r][j];
    45             mp[N[i].r][1]=gg;    
    46         }
    47         if(N[i].type==2)
    48         {
    49             int gg=mp[n][N[i].l];
    50              for(int j=n-1;j>=1;j--)
    51                mp[j+1][N[i].l]=mp[j][N[i].l];
    52             mp[1][N[i].l]=gg;        
    53         }
    54         if(N[i].type==3)
    55         {
    56             mp[N[i].r][N[i].l]=N[i].value;
    57         }
    58      }
    59      for(int i=1;i<=n;i++)
    60      {
    61          cout<<mp[i][1];
    62          for(int j=2;j<=m;j++)
    63          cout<<" "<<mp[i][j];
    64          cout<<endl;
    65      }
    66      return 0;
    67  }


  • 相关阅读:
    红黑树深入剖析及Java实现
    Innodb中的事务隔离级别和锁的关系
    从实际案例聊聊Java应用的GC优化
    Java HotSpot VM Options 参数设置
    jvm 字节码查看
    JDK8-废弃永久代(PermGen)迎来元空间(Metaspace)
    jsp 预编译
    MySQL中有关TIMESTAMP和DATETIME的总结
    MySQL 索引及优化实战
    spring boot 配置https 报这个错误:java.lang.IllegalArgumentException: Private key must be accompanied by certificate chain
  • 原文地址:https://www.cnblogs.com/hsd-/p/5429215.html
Copyright © 2011-2022 走看看