标签:span cti order function input with script ini print
Input
Output
Escaped in x minute(s).
Trapped!
Sample Input
3 4 5
S....
.###.
.##..
###.#
#####
#####
##.##
##...
#####
#####
#.###
####E
1 3 3
S##
#E#
###
0 0 0
Sample Output
Escaped in 11 minute(s).
Trapped!
BFS:
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> #include <queue> #include <map> #include <sstream> #include <cstdio> #include <cstring> #include <numeric> #include <cmath> #include <iomanip> //#include <unordered_set> //#include <unordered_map> //#include <xfunctional> using namespace std; int dir[6][3] = { { 0,0,1 },{ 0,0,-1 },{ 0,-1,0 },{ 0,1,0 },{1,0,0},{-1,0,0} }; const long long INF = 0x7f7f7f7f7f7f7f7f; const int inf = 0x3f3f3f3f; const double pi = 3.14159265358979; #define ll long long; #define PII pair<int, int>; const int mod = 1e9 + 7; const int marown = 1000 + 5; //if(x<0 || x>=r || y<0 || y>=c) struct node { int x, y, z,cnt; }; int l, r, c,S,E,sx,sy,sz,ex,ey,ez; vector<vector<string>> v(35,vector<string>(35)); int res=inf; void bfs(vector<vector<vector<bool>>>& visited, queue<node>& que) { while(!que.empty()) { if (v[que.front().z][que.front().x][que.front().y]==‘E‘) { res = min(res,que.front().cnt); } for (int t = 0; t < 6; t++) { node tmp; tmp.x = que.front().x + dir[t][0]; tmp.y = que.front().y + dir[t][1]; tmp.z = que.front().z + dir[t][2]; tmp.cnt=que.front().cnt + 1; if (tmp.z >= 0 && tmp.z < l && tmp.x >= 0 && tmp.x < r && tmp.y >= 0 && tmp.y < c && v[tmp.z][tmp.x][tmp.y] != ‘#‘ && visited[tmp.z][tmp.x][tmp.y] == false) { visited[tmp.z][tmp.x][tmp.y] = true; que.push(tmp); } } que.pop(); } } int main() { while (cin >> l >> r >> c && l != 0 && r != 0 && c != 0) { for (int k = 0; k < l; k++) { for(int i=0;i<r;i++) { cin >> v[k][i]; for (int j = 0; j < c; j++) { if (v[k][i][j] == ‘S‘) { sx = i, sy = j,sz=k; v[k][i][j] = ‘S‘; } else if (v[k][i][j] == ‘E‘) { ex = i, ey = j,ez=k; v[k][i][j] = ‘E‘; } } } } queue<node> que; res = inf; vector<vector<vector<bool>>> visited(35,vector<vector<bool>>(35,vector<bool>(35,false))); node start; start.x = sx; start.y = sy; start.z = sz; start.cnt = 0; que.push(start); bfs(visited,que); if (res == inf) cout << "Trapped!" << endl; else cout << "Escaped in " << res<< " minute(s)." << endl; } return 0; }
标签:span cti order function input with script ini print
原文地址:https://www.cnblogs.com/dealer/p/12547718.html