-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ3055_탈출.cpp
More file actions
124 lines (113 loc) · 3.05 KB
/
BOJ3055_탈출.cpp
File metadata and controls
124 lines (113 loc) · 3.05 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// main.cpp
// BOJ3055_탈출
//
// Created by 신지식 on 2018. 10. 4..
// Copyright © 2018년 Shin Ji Sik. All rights reserved.
//
#include <iostream>
#include <queue>
using namespace std;
int r, c;
char arr[51][51];
int moving[51][51];
bool check[51][51];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
queue<pair<int, int>> s;
queue<pair<int, int>> water;
int ax = 0, ay = 0;
int cnt = 0;
void bfs(int x, int y){
printf("%d %d\n", ax, ay);
s.push(make_pair(x, y));
int nx = 0, ny = 0;
int flag = 0;
while(!s.empty()){
int w_s = water.size();
printf("-- %d--\n", w_s);
while(w_s--){
x = water.front().first;
y = water.front().second;
water.pop();
for(int i = 0; i < 4; i++){
nx = x + dx[i];
ny = y + dy[i];
if(nx < 0 && nx >= c && ny < 0 && ny >= r) continue;
if(arr[nx][ny] == '.' || arr[nx][ny] == 'S'){
if(check[nx][ny] == false){
moving[nx][ny] = 0;
check[nx][ny] = true;
water.push(make_pair(nx, ny));
}
}
}
}
x = s.front().first;
y = s.front().second;
s.pop();
int notcnt = 0;
if(notcnt == 4){
flag = 1;
break;
}
for(int i = 0; i < 4; i++){
nx = x + dx[i];
ny = y + dy[i];
if(nx < 0 && nx >= c && ny < 0 && ny >= r){
notcnt++;
continue;
}
if(arr[nx][ny] == '.' && check[nx][ny] == false){
moving[nx][ny] = moving[x][y] + 1;
s.push(make_pair(nx, ny));
cnt++;
}
if(moving[nx][ny] == 0){
notcnt++;
}
}
printf("->>>> %d %d %d\n", s.size(), x, y);
printf("----------------\n");
for(int i = 0; i < c; i++){
for(int j = 0; j < r; j++){
printf("%d ", moving[i][j]);
}
printf("\n");
}
printf("\n");
cnt++;
}
if(flag == 1)
printf("%d\n", cnt-1);
else
printf("KAKTUS\n");
}
int main(int argc, const char * argv[]) {
cin >> c >> r;
int x = 0, y = 0;
for(int i = 0; i < c; i++){
for(int j = 0; j < r; j++){
cin >> arr[i][j];
if(arr[i][j] == 'D'){
moving[i][j] = 3;
ax = i, ay = j;
}
else if(arr[i][j] == 'S'){
moving[i][j] = 1;
x = i, y = j;
}
else if(arr[i][j] == '*'){
moving[i][j] = 0;
water.push(make_pair(i, j));
}
else if(arr[i][j] == 'X'){
moving[i][j] = 4;
check[i][j] = true;
}
else
moving[i][j] = -1;
}
}
bfs(x, y);
}