알고리즘 공부

백준 상범 빌딩

컴퓨터과학 2023. 7. 18. 21:14

https://www.acmicpc.net/problem/6593

 

6593번: 상범 빌딩

당신은 상범 빌딩에 갇히고 말았다. 여기서 탈출하는 가장 빠른 길은 무엇일까? 상범 빌딩은 각 변의 길이가 1인 정육면체(단위 정육면체)로 이루어져있다. 각 정육면체는 금으로 이루어져 있어

www.acmicpc.net

흠 ㅋㅋㅋ 출력문 마지막 . 안붙여서 틀렷다 나왔엇네요 ㅋㅋㅋㅋㅋㅋㅋ어이가없네요 

Escaped in "+to_string(start.cnt) +" minute(s).

정답

#include <iostream>
#include <vector>
#include <queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<map>
using namespace std;

struct Point {
	int i, j,t, cnt;
	char c;
};

void Prints(vector<vector<int>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j];
		}
		cout << endl;
	}
	cout << endl;
}

void Prints(vector<vector<bool>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j];
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<vector<char>>maps, int n, int m) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << maps[i][j];
		}
		cout << endl;
	}
	cout << endl;
}
void Prints(vector<vector<vector<char>>>maps, int n, int m,int k) {
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << maps[t][i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
	
}
void Prints(vector<vector<vector<bool>>>maps, int n, int m, int k) {
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cout << maps[t][i][j];
			}
			cout << endl;
		}
		cout << endl;
	}
	cout << endl;
}
struct Data {
	string str;
	int cnt;
};

struct Word {
	std::string word;
	int count;
};
int main() {
	vector<string>anw;
	int worldCount = 0;
	while(true){
	int n, m, k;
	cin >> k >> n >> m; //3 4 5 
	if (k == 0 && m == 0 && n == 0) break;
	vector<vector<vector<char>>>maps;
	vector<bool>tmpbCheck1(m,false);
	vector<vector<bool>>tmpbCheck2(n, tmpbCheck1);
	vector<vector<vector<bool>>>bCheck(k, tmpbCheck2);
	for (int i = 0; i < k; i++) {
		vector<vector<char>> tmpmaps1;
		for (int j = 0; j < n; j++) {
			vector<char> tmpmaps2;
			
			string str;
			cin >> str;

			for (int c = 0; c < str.size(); c++) {
				tmpmaps2.push_back(str[c]);
				if (str[c] == '#') {
					bCheck[i][j][c]=true;
				}
			}
			tmpmaps1.push_back(tmpmaps2);
		}
		maps.push_back(tmpmaps1);
	}
	//Prints(tmpmaps1, n, m);
	//Prints(maps, n, m, k);
	//cout << endl;
	bool bEnd = false;
	bool bStart = false;
	
	for (int t = 0; t < k; t++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (maps[t][i][j] == 'S') {
					queue<Point>q;
					Point p;
					p.i = i;
					p.j = j;
					p.t = t;
					p.cnt = 1;
					q.push(p);
					int diri[] = { 0,0,1,-1,0,0};
					int dirj[] = { 0,0,0,0,1,-1 };
					int dirt[] = { 1,-1,0,0,0,0 };
					bStart = true;
					while (!q.empty()) {
						Point start = q.front();
						q.pop();
						if (bEnd == true) {
							
							break;
						}
						for (int v = 0; v < 6; v++) {
							int tmpdiri = start.i+diri[v];
							int tmpdirj = start.j + dirj[v];
							int tmpdirt = start.t + dirt[v];
							if (tmpdiri==-1|| tmpdirj==-1|| tmpdirt==-1|| tmpdiri>n-1|| tmpdirj>m-1|| tmpdirt>k-1) {
								continue;
							}
							if (maps[tmpdirt][tmpdiri][tmpdirj] == 'E') {
								//cout << maps[tmpdirt][tmpdiri][tmpdirj] << endl;
								//cout << "Escaped in "<< start.cnt<<" minute(s)";
								anw.push_back("Escaped in "+to_string(start.cnt) +" minute(s).");
								bEnd = true;
								v = 7;
							}

							if (bCheck[tmpdirt][tmpdiri][tmpdirj] == false&&maps[tmpdirt][tmpdiri][tmpdirj]=='.') {
								bCheck[tmpdirt][tmpdiri][tmpdirj] = true;
								Point tmpp;
								tmpp.i = tmpdiri;
								tmpp.j = tmpdirj;
								tmpp.t = tmpdirt;
								tmpp.cnt = start.cnt + 1;
								q.push(tmpp);
								//(bCheck, n, m, k);
							}
						}
					}

			     }
			}
		}
	}
	if (bEnd == false&& bStart==true) {
		//cout << "Trapped!";
		anw.push_back("Trapped!");
	}
	//worldCount++;
	//if (worldCount = 100000) { break; }
	}
	for (int i = 0; i < anw.size(); i++) {
		cout << anw[i] << endl;
	}
	return 0;
}