Codeforces 631B Print Check (思维)

题目链接 Print Check

注意到行数加列数最大值只有几千,那么有效的操作数只有几千,那么把这些有效的操作求出来依次模拟就可以了。

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 #define rep(i,a,b)              for(int i(a); i <= (b); ++i)
 6 const int N     =    100000      +       10;
 7 const int Q     =    5000        +       10;
 8 
 9 struct node{
10     int op, x, y;
11 } a[N];
12 
13 int col[Q][Q];
14 int v[N];    //v[i] = 1 则第i个操作需要被执行
15 int c[3][Q];
16 int n, m, k, op, x, y;
17 
18 int main(){
19 
20     scanf("%d%d%d", &n, &m, &k);
21     rep(i, 1, k){
22         scanf("%d%d%d", &op, &x, &y);
23         c[op][x] = i;
24         a[i].op = op, a[i].x = x, a[i].y = y;
25     }
26 
27     rep(i, 1, n) if (c[1][i]) v[c[1][i]] = 1;
28     rep(i, 1, m) if (c[2][i]) v[c[2][i]] = 1;
29 
30     rep(i, 1, k) if (v[i]){
31         if (a[i].op == 1){
32             rep(j, 1, m) col[a[i].x][j] = a[i].y;
33         }
34         else{
35             rep(j, 1, n) col[j][a[i].x] = a[i].y;
36         }
37     }
38 
39     rep(i, 1, n){
40         rep(j, 1, m) printf("%d ", col[i][j]);
41         putchar(10);
42     }
43 
44     return 0;
45 
46 }

 

posted @ 2017-01-26 23:26  cxhscst2  阅读(247)  评论(0编辑  收藏  举报