Codeforces 669C Little Artem and Matrix (模拟)

题意

对一个矩阵有三种操作
1.第row行循环右移x位
2.第col列循环下移x位
3.告诉你第row行的第col列的数是x。
要求构造出符合操作的原矩阵。

思路

因为数据很小,直接暴力就可以了,按照操作倒着模拟一遍,有3操作的就填数,没有的就为0。

代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define LL long long
#define Lowbit(x) ((x)&(-x))
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1|1
#define MP(a, b) make_pair(a, b)
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const int maxn = 1e5 + 10;
const double eps = 1e-8;
const double PI = acos(-1.0);
typedef pair<int, int> pii;
int a[110][110];

struct node
{
    int type;
    int r, c, x;
}p[10010];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    memset(a, 0, sizeof(a));
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 0; i < q; i++)
    {
        int t;
        scanf("%d", &t);
        if (t == 3)
        {
            p[i].type = 3;
            scanf("%d%d%d", &p[i].r, &p[i].c, &p[i].x);
        }
        if (t == 2)
        {
            p[i].type = 2;
            scanf("%d", &p[i].c);
        }
        if (t == 1)
        {
            p[i].type = 1;
            scanf("%d", &p[i].r);
        }
    }
    for (int i = q - 1; i >= 0; i--)
    {
        if (p[i].type == 1)
        {
            int row = p[i].r;
            int t = a[row][m];
            for (int i = m; i >= 2; i--)
                a[row][i] = a[row][i-1];
            a[row][1] = t;
        }
        if (p[i].type == 2)
        {
            int col = p[i].c;
            int t = a[n][col];
            for (int i = n; i >= 2; i--)
                a[i][col] = a[i-1][col];
            a[1][col] = t;
        }
        if (p[i].type == 3)
        {
            a[p[i].r][p[i].c] = p[i].x;
        }
    }
    for (int i = 1; i <= n; i++, printf("\n"))
        for (int j = 1; j <= m; j++)
            printf("%d ", a[i][j]);
    return 0;
}

你可能感兴趣的:(codeforces)