Codeforces631B Print Check

March 04, 2016

题目链接

题意:query 1 是把某行涂成一个色,2 是把一列涂成一个色,后涂的颜色覆盖前面的颜色。

一次遍历就可以解决,对于每个点,比较行列颜色的顺序,输入顺序大的那个的颜色。

#include<cstring>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int n, m, k;
int r1[5005], c1[5005];  //i行(列)的颜色
int r1rank[5005], c1rank[5005]; //涂色顺序
int main(){
    //freopen("a.txt", "r", stdin);
    while(scanf("%d%d%d", &n, &m, &k) != EOF){
        memset(c1, 0, sizeof(c1));
        memset(r1rank, 0, sizeof(r1rank));
        memset(c1rank, 0, sizeof(c1rank));
        memset(r1, 0, sizeof(r1));
        for(int i =1 ; i<=k;i++){
            int a, b ,c;
            scanf("%d%d%d", &a, &b, &c);
            //cout << a << b << c <<endl;
            if(a == 1){
                r1[b] = c;
                r1rank[b] = i;
            }else if(a==2){
                c1[b] = c;
                c1rank[b] = i;
            }
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(r1rank[i] > c1rank[j])
                    cout << r1[i];
                else cout << c1[j];
                //cout << pic[i][j];
                if(j != m) cout << " ";
            }
            cout << endl;
        }

    }
    return 0;
}

Profile picture

Written by Armin Li , a venture capitalist. [Weibo] [Subscribe]