-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16433.cpp
63 lines (54 loc) · 900 Bytes
/
16433.cpp
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
// 16433. 주디와 당근농장
// 2019.08.24
// BFS
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
char map[101][101];
bool visit[101][101];
int dx[4] = { 1,1,-1,-1 };
int dy[4] = { -1,1,1,-1 };
int main()
{
int n, r, c;
cin >> n >> r >> c;
for (int i = 0; i < 101; i++)
{
fill(map[i], map[i] + 101, '.');
}
queue<pair<int, int>> q;
q.push({ r,c });
map[r][c] = 'v';
visit[r][c] = 1;
while (!q.empty())
{
int x = q.front().first;
int y = q.front().second;
q.pop();
for (int i = 0; i < 4; i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if (xx<1 || yy<1 || xx>n || yy>n)
{
continue;
}
if (!visit[xx][yy])
{
visit[xx][yy] = 1;
q.push({ xx,yy });
map[xx][yy] = 'v';
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cout << map[i][j];
}
cout << "\n";
}
return 0;
}