using
System;
public
class
Program
{
public
static
bool
Valid(
int
x,
int
y,
int
n)
{
if
(x < 1 || y < 1 || x > n || y > n)
{
return
false
;
}
return
true
;
}
public
static
int
Count(
int
n,
int
cx,
int
cy,
bool
[][] board)
{
int
ct = 0;
for
(
int
x = cx; x < cx + 3; x++)
{
for
(
int
y = cy; y < cy + 3; y++)
{
if
(Valid(x, y, n))
{
if
(board[x][y])
{
ct++;
}
}
}
}
return
ct;
}
public
static
int
MinimumMoveSquare(
int
n,
int
m,
int
[][] moves)
{
int
x = 0, y = 0;
bool
[][] board =
new
bool
[n + 1][];
for
(
int
i = 1; i <= n; i++)
{
board[i] =
new
bool
[n + 1];
for
(
int
j = 1; j <= n; j++)
{
board[i][j] =
false
;
}
}
for
(
int
i = 0; i < m; i++)
{
x = moves[i][0];
y = moves[i][1];
board[x][y] =
true
;
for
(
int
cx = x - 2; cx <= x; cx++)
{
for
(
int
cy = y - 2; cy <= y; cy++)
{
if
(Count(n, cx, cy, board) == 9)
{
return
i + 1;
}
}
}
}
return
-1;
}
public
static
void
Main()
{
int
n = 3;
int
[][] moves =
new
int
[3][];
moves[0] =
new
int
[] { 1, 1 };
moves[1] =
new
int
[] { 1, 2 };
moves[2] =
new
int
[] { 1, 3 };
int
m = moves.Length;
Console.WriteLine(MinimumMoveSquare(n, m, moves));
}
}