#include <stdio.h>
#define SIZE 16
const int dy[4] = { -1,0,1,0 }; // 상 우 하 좌
const int dx[4] = { 0,1,0,-1 };
int maze[SIZE][SIZE];
int xQ[SIZE * SIZE + 10]; // * 에다가 스페이스 + 한 것임
int yQ[SIZE * SIZE + 10];
int front, rear;
void nQ(int yy, int xx)
{
xQ[rear] = xx;
yQ[rear] = yy;
maze[yy][xx] = 1;
++rear; // 넣을 때 rear++를 하고,
}
int main()
{
freopen("input.txt", "r", stdin);
int T, test_case;
int nx, ny;
int flag;
int desx, desy;
int i, j;
for (T = 1; T <= 10; ++T)
{
front = rear = 0;
flag = 0;
scanf("%d", &test_case);
for (i = 0; i < SIZE; ++i)
{
for (j = 0; j < SIZE; ++j)
{
scanf("%1d", &maze[i][j]);
if (maze[i][j] == 2)
nQ(i, j);
if (maze[i][j] == 3)
{
desy = i; // 세로
desx = j; // 가로
}
}
}
while (front < rear)
{
if ((yQ[front] == desy) && (xQ[front] == desx))
{
flag = 1;
break;
}
for (i = 0; i < 4; ++i)
{
ny = yQ[front] + dy[i];
nx = xQ[front] + dx[i];
if (maze[ny][nx] != 1) // 1이 아니면 이동 가능
nQ(ny, nx);
}
++front; //하나의 front에 대해서 상하좌우 4방향에 대해서 검사를 진행함
}
printf("#%d %d\n", test_case, flag);
}
return 0;
}
댓글