题目传送门
/*
模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0
很挫的判断四个方向是否OK
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN][MAXN];
bool lose(int i, int j, int n, int m)
{
if (a[i][j] == )
{
if (j < m && a[i][j+] == )
{
if (i < n && a[i+][j] == )
{
if (a[i+][j+] == )
{
return true;
}
}
}
if (j> && a[i][j-] == )
{
if (i < n && a[i+][j-] == )
{
if (a[i+][j] == )
{
return true;
}
}
}
if (j > && a[i][j-] == )
{
if (i > && a[i-][j-] == )
{
if (a[i-][j] == )
{
return true;
}
}
}
if (j < m && a[i][j+] == )
{
if (i > && a[i-][j] == )
{
if (a[i-][j+] == )
{
return true;
}
}
}
}
return false;
}
int main(void)
{
#ifndef ONLINE_JUDGE
freopen ("A.in", "r", stdin);
#endif
int n, m, k;
while (~scanf ("%d%d%d", &n, &m, &k))
{
memset (a, , sizeof (a));
bool flag = false; int ans = -;
for (int i=; i<=k; ++i)
{
int x, y;
scanf ("%d%d", &x, &y);
if (a[x][y] == ) continue;
a[x][y] = ;
if (lose (x, y, n, m) && !flag)
{
flag = true; ans = i;
}
}
if (!flag) printf ("%d\n", );
else printf ("%d\n", ans);
}
return ;
}