Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define MAX 55
- string a[MAX][MAX];
- int r, c, h, d[MAX][MAX][MAX],vis[MAX][MAX][MAX];
- struct co{
- int i,j,k,d;
- void init(int a,int b,int c,int _d){
- i = a,j = b, k = c, d = _d;
- }
- };
- int main(){
- int n, x, y, z, close, di;
- memset(d, -1 , sizeof d);
- cin >> r >> c >> h;
- co st,u,v;
- for(int i = 1;i <= h; ++i){
- for(int j = 1;j <= r; ++j){
- cin >> a[i][j];
- for(int k = 0;k < c; ++k){
- if(a[i][j][k] == '*')
- st.init(i,j,k,0);
- vis[i][j][k] = -1;
- }
- }
- }
- d[st.i][st.j][st.k] = 0;
- queue<co> q;
- q.push(st);
- while(!q.empty()){
- u = q.front();
- q.pop();
- x = u.i, y = u.j, z = u.k, di = u.d;
- if(x <= 0 || x > h || y <= 0 || y > r || z < 0 || z >= c || a[x][y][z] == '#' || vis[x][y][z] == 1)
- continue;
- d[x][y][z] = di;
- v.init(x + 1,y,z,di + 1);
- q.push(v);
- v.init(x - 1,y,z,di + 1);
- q.push(v);
- v.init(x,y + 1,z,di + 1);
- q.push(v);
- v.init(x,y - 1,z,di + 1);
- q.push(v);
- v.init(x,y,z + 1,di + 1);
- q.push(v);
- v.init(x,y,z - 1,di + 1);
- q.push(v);
- vis[x][y][z] = 1;
- }
- close = INT_MAX;
- cin >> n;
- string s,name;
- name = "None!";
- while(n--){
- cin >> s >> x >> y >> z;
- if(d[z][x][y - 1] != -1 && close > d[z][x][y - 1])
- close = d[z][x][y - 1], name = s;
- else if(d[z][x][y - 1] != -1 && close == d[z][x][y - 1] && s < name)
- close = d[z][x][y - 1], name = s;
- }
- cout << name << " ";
- if(close < INT_MAX)
- cout << close << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement