题目传送门
1 /*
2 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0
3 很挫的判断四个方向是否OK
4 */
5 #include <cstdio>
6 #include <iostream>
7 #include <algorithm>
8 #include <cmath>
9 #include <cstring>
10 #include <map>
11 using namespace std;
12
13 const int MAXN = 1e3 + 10;
14 const int INF = 0x3f3f3f3f;
15 int a[MAXN][MAXN];
16
17 bool lose(int i, int j, int n, int m)
18 {
19 if (a[i][j] == 1)
20 {
21 if (j < m && a[i][j+1] == 1)
22 {
23 if (i < n && a[i+1][j] == 1)
24 {
25 if (a[i+1][j+1] == 1)
26 {
27 return true;
28 }
29 }
30 }
31 if (j>1 && a[i][j-1] == 1)
32 {
33 if (i < n && a[i+1][j-1] == 1)
34 {
35 if (a[i+1][j] == 1)
36 {
37 return true;
38 }
39 }
40 }
41 if (j > 1 && a[i][j-1] == 1)
42 {
43 if (i > 1 && a[i-1][j-1] == 1)
44 {
45 if (a[i-1][j] == 1)
46 {
47 return true;
48 }
49 }
50 }
51 if (j < m && a[i][j+1] == 1)
52 {
53 if (i > 1 && a[i-1][j] == 1)
54 {
55 if (a[i-1][j+1] == 1)
56 {
57 return true;
58 }
59 }
60 }
61 }
62
63 return false;
64 }
65
66 int main(void)
67 {
68 #ifndef ONLINE_JUDGE
69 freopen ("A.in", "r", stdin);
70 #endif
71
72 int n, m, k;
73 while (~scanf ("%d%d%d", &n, &m, &k))
74 {
75 memset (a, 0, sizeof (a));
76
77 bool flag = false; int ans = -1;
78 for (int i=1; i<=k; ++i)
79 {
80 int x, y;
81 scanf ("%d%d", &x, &y);
82 if (a[x][y] == 1) continue;
83
84 a[x][y] = 1;
85 if (lose (x, y, n, m) && !flag)
86 {
87 flag = true; ans = i;
88 }
89 }
90
91 if (!flag) printf ("%d\n", 0);
92 else printf ("%d\n", ans);
93 }
94
95 return 0;
96 }