반응형
https://www.acmicpc.net/problem/3055
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int R,C;
char mymap[50][50];
int dy[4] = {0,0,1,-1};
int dx[4] = {1,-1,0,0};
struct con
{
int y;
int x;
int cnt;
};
void W_BFS(int y,int x,int cnt,queue <con>& Q_w){
if(y>=R||y<0||x>=C||x<0) return;
if(mymap[y][x] =='S'|| mymap[y][x]=='.') {
mymap[y][x] = '*';
}
}
bool S_BFS(int y,int x,int cnt,queue <con>& Q_s){
if(y>=R||y<0||x>=C||x<0) return false;
if(mymap[y][x] == 'D'){
return true;
}
if(mymap[y][x] == '.'){
mymap[y][x] = 'S';
return false;
}
return false;
}
int main(void){
cin>>R>>C;
queue <con> Q_s;
queue <con> Q_w;
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
cin>>mymap[i][j];
if(mymap[i][j] == 'S'){
Q_s.push({i,j,0});
}else if(mymap[i][j] == '*'){
Q_w.push({i,j,0});
}
}
}
con tmp_s;
con tmp_w;
int cnt=0;
bool check= false;
while(true){
int ny,nx;
while(true){
else if(cnt == Q_w.front().cnt){
tmp_w = Q_w.front();
Q_w.pop();
for(int i=0;i<4;i++){
ny = dy[i] + tmp_w.y;
nx = dx[i] + tmp_w.x;
W_BFS(ny,nx,cnt,Q_w);
}
}else break;
}
while(true){
if(Q_s.empty()){
cout<<"KAKTUS";
check = true;
break;
}
else if(cnt == Q_s.front().cnt){
tmp_s = Q_s.front();
Q_s.pop();
for(int i=0;i<4;i++){
ny = dy[i] + tmp_s.y;
nx = dx[i] + tmp_s.x;
if(S_BFS(ny,nx,cnt,Q_s)){
cout<<cnt+1;
check = true;
break;
}
}
}else break;
if(check) break;
}
++cnt;
if(check) break;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형
'ProgramSoliving' 카테고리의 다른 글
백준 : 16234 * (0) | 2020.01.11 |
---|---|
백준 : 9251 (0) | 2020.01.01 |
백준 : 2468 (0) | 2020.01.01 |
백준 : 14888 (0) | 2019.12.25 |
백준 : 14889 (0) | 2019.12.25 |