반응형
https://www.acmicpc.net/problem/6593
상범 빌딩 단순한 큐구현후 BFS를 구현하면된다.
3차원평면이기때문에 check[][][] 3차원으로 구현하면 중복을 방지할수가 있다.
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
|
package com.ssay.algo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class B6593 {
public static class XYZ{
int z;
int y;
int x;
int cnt;
public XYZ(int z, int y, int x,int cnt) {
super();
this.z = z;
this.y = y;
this.x = x;
this.cnt = cnt;
}
}
static int L,R,C;
static char map[][][];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while(true) {
StringTokenizer st = new StringTokenizer(br.readLine());
L = Integer.parseInt(st.nextToken());
R = Integer.parseInt(st.nextToken());
C = Integer.parseInt(st.nextToken());
if(L==0&&R==0&&C==0) break;
XYZ Start = null;
map = new char[L][R][C];
for(int l=0;l<L;l++) {
for(int i=0;i<R;i++) {
map[l][i] = br.readLine().toCharArray();
for(int j=0;j<C;j++) {
if(map[l][i][j] == 'S') {
Start = new XYZ(l,i,j,0);
}
}
}
br.readLine();
}
int dx[] = {0,0,0,0,1,-1};
int dy[] = {0,0,1,-1,0,0};
int dz[] = {1,-1,0,0,0,0};
Queue<XYZ> q = new LinkedList<XYZ>();
q.clear();
boolean check[][][] = new boolean[L][R][C];
boolean isPosible = false;
check[Start.z][Start.y][Start.x] = true;
q.add(new XYZ(Start.z,Start.y,Start.x,0));
int result = 0;
while(!q.isEmpty()) {
XYZ tmp = q.poll();
if(map[tmp.z][tmp.y][tmp.x] == 'E') {
isPosible = true;
result = tmp.cnt;
break;
}
for(int d=0;d<6;d++) {
int nz = tmp.z + dz[d];
int ny = tmp.y + dy[d];
int nx = tmp.x + dx[d];
if(nz<0||ny<0||nx<0||nz>=L||ny>=R||nx>=C) continue;
if(check[nz][ny][nx] == true) continue;
if(map[nz][ny][nx] == '#') continue;
check[nz][ny][nx] = true;
}
}
// 답
if(isPosible) {
System.out.println("Escaped in "+result+" minute(s).");
}else {
System.out.println("Trapped!");
}
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
반응형
'ProgramSoliving' 카테고리의 다른 글
백준 : 16637 (0) | 2020.02.09 |
---|---|
백준 : 17471 (0) | 2020.02.09 |
백준 : 1504 (0) | 2020.02.08 |
백준 : 1261 (0) | 2020.02.08 |
백준 : 1238 (0) | 2020.02.08 |