-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1227.cpp
More file actions
95 lines (89 loc) · 1.58 KB
/
1227.cpp
File metadata and controls
95 lines (89 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// 1227. 미로2
// 2019.07.23
#include<iostream>
#include<string>
#include<queue>
using namespace std;
int map[101][101];
int visit[101][101];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
pair<int, int> startPos;
pair<int, int> endPos;
int main()
{
for (int test = 1; test <= 10; test++)
{
int n;
cin >> n;
for (int i = 0; i < 101; i++)
{
fill(map[i], map[i] + 101, -1);
fill(visit[i], visit[i] + 101, 0);
}
for (int i = 0; i < 100; i++)
{
string s;
cin >> s;
for (int j = 0; j < 100; j++)
{
map[i][j] = s[j] - '0';
if (map[i][j] == 2)
{
startPos.first = i;
startPos.second = j;
}
if (map[i][j] == 3)
{
endPos.first = i;
endPos.second = j;
}
}
}
queue<pair<int, int>> q;
q.push({ startPos.first,startPos.second });
visit[startPos.first][startPos.second] = 1;
bool flag = false;
while (!q.empty())
{
int first = q.front().first;
int second = q.front().second;
q.pop();
// 도착
if (first == endPos.first && second == endPos.second)
{
flag = true;
break;
}
// 4방향 탐색
for (int i = 0; i < 4; i++)
{
int xx = first + dx[i];
int yy = second + dy[i];
if (xx < 0 || yy < 0 || xx >= 100 || yy >= 100)
{
continue;
}
if (map[xx][yy] == 1)
{
continue;
}
if (!visit[xx][yy])
{
visit[xx][yy] = 1;
q.push({ xx,yy });
}
}
}
// 도착했다면 1, 도착할수 없다면 0
if (flag)
{
cout << "#" << test << " 1" << endl;
}
else
{
cout << "#" << test << " 0" << endl;
}
}
return 0;
}