题目链接:https://ac.nowcoder.com/acm/contest/877/H
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

Marzz liked a strange way of memorizing words.

 Now these words are placed in an  Matrix. He decided to memorize only one line or one column of words every day. She has memorized days in total, and now she wants to know: for each word, when was the last time she memorized it?

输入描述

输出描述

输入

3 3 3
1 2
2 3
1 3

输出

0 0 2
1 1 2
3 3 3

解题思路

题意:每天只能背一行或者一列的单词,求一个代表单词的矩阵,其值为这个单词最后背是第几天.
思路:可以申请两个一维数组,来表示第几行第几列是第几天背诵的,然后输出的时候判断一下该单词的行和列哪个是后来背的。

#include <bits/stdc++.h>
using namespace std;
int a[2][100005];
int main() {
    int n, m, t, v, w;
    scanf("%d%d%d", &n, &m, &t);
    for (int i = 1; i <= t; i++) {
        scanf("%d%d", &v, &w);
        a[v - 1][w] = i;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            printf("%d ", max(a[0][i], a[1][j]));
        printf("\n");
    }
    return 0;
}