-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1210.cpp
More file actions
60 lines (56 loc) · 864 Bytes
/
1210.cpp
File metadata and controls
60 lines (56 loc) · 864 Bytes
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
// 1210. Ladder1
// 2019.07.27
#include<iostream>
using namespace std;
int map[102][102];
int visit[102][102];
int ans;
void go(int x, int y)
{
if (x == 1)
{
ans = y - 1;
return;
}
visit[x][y] = 1;
if (map[x][y + 1] == 1 && visit[x][y + 1] != 1)
{
go(x, y + 1);
}
else if (map[x][y - 1] == 1 && visit[x][y - 1] != 1)
{
go(x, y - 1);
}
else if (map[x - 1][y] == 1 && visit[x - 1][y] != 1)
{
go(x - 1, y);
}
}
int main()
{
for (int t = 1; t <= 10; t++)
{
ans = 0;
for (int i = 0; i < 102; i++)
{
fill(visit[i], visit[i] + 102, 0);
fill(map[i], map[i] + 102, 0);
}
int n;
cin >> n;
for (int i = 1; i <= 100; i++)
{
for (int j = 1; j <= 100; j++)
{
cin>>map[i][j];
// 사다리 출발
if (map[i][j] == 2)
{
go(i, j);
}
}
}
cout << "#" << t << " " << ans << endl;
}
return 0;
}