codeforces#348-C. Little Artem and Matrix-模拟

http://codeforces.com/contest/669/problem/C


给你q个操作,每次移动矩阵一列或一行 一个位置,

告诉你r行c列的数为多少,

让你还原出这个 n*m的矩阵



直接模拟,从最后一部开始模拟即可

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;

struct node
{
    int op,rc;
    int r,c,val;
};
node tm[10005];
int mp[105][105];
    int n,m,q;
void shiftcol(int x)
{
    int val=mp[n][x];
        for (int i=n-1;i>=1;i--)
            mp[i+1][x]=mp[i][x];
        mp[1][x]=val;
}
void shiftrow(int x)
{
    int val=mp[x][m];
        for (int i=m-1;i>=1;i--)
            mp[x][i+1]=mp[x][i];
        mp[x][1]=val;
}
int main()
{

    cin>>n>>m>>q;
    int i,j ;
    for (i=1; i<=q;i++)
    {
        int a,b,c,d,e;
        scanf("%d",&tm[i].op);
        if (tm[i].op==1||tm[i].op==2)
            scanf("%d",&tm[i].rc);
        else
            scanf("%d%d%d",&tm[i].r,&tm[i].c,&tm[i].val);

    }
    for (i=q;i>=1;i--)
    {
        if (tm[i].op==3)
        {
            int x=tm[i].r;
            int y=tm[i].c;
            mp[x][y]=tm[i].val;
        }
        else
            if (tm[i].op==2)
            shiftcol(tm[i].rc);
            else
            shiftrow(tm[i].rc);
    }

for (i=1;i<=n;i++)
{
    for (j=1;j<=m;j++)
    {
        if (j>1) printf(" ");
        printf("%d",mp[i][j]);
    }
    printf("\n");
}









    return 0;

}


你可能感兴趣的:(codeforces#348-C. Little Artem and Matrix-模拟)