Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define MAX 55
  4. string a[MAX][MAX];
  5. int r, c, h, d[MAX][MAX][MAX],vis[MAX][MAX][MAX];
  6. struct co{
  7. int i,j,k,d;
  8. void init(int a,int b,int c,int _d){
  9. i = a,j = b, k = c, d = _d;
  10. }
  11. };
  12. int main(){
  13.  
  14. int n, x, y, z, close, di;
  15. memset(d, -1 , sizeof d);
  16. cin >> r >> c >> h;
  17. co st,u,v;
  18. for(int i = 1;i <= h; ++i){
  19. for(int j = 1;j <= r; ++j){
  20. cin >> a[i][j];
  21. for(int k = 0;k < c; ++k){
  22. if(a[i][j][k] == '*')
  23. st.init(i,j,k,0);
  24. vis[i][j][k] = -1;
  25. }
  26. }
  27. }
  28. d[st.i][st.j][st.k] = 0;
  29. queue<co> q;
  30. q.push(st);
  31. while(!q.empty()){
  32. u = q.front();
  33. q.pop();
  34. x = u.i, y = u.j, z = u.k, di = u.d;
  35. if(x <= 0 || x > h || y <= 0 || y > r || z < 0 || z >= c || a[x][y][z] == '#' || vis[x][y][z] == 1)
  36. continue;
  37. d[x][y][z] = di;
  38. v.init(x + 1,y,z,di + 1);
  39. q.push(v);
  40. v.init(x - 1,y,z,di + 1);
  41. q.push(v);
  42. v.init(x,y + 1,z,di + 1);
  43. q.push(v);
  44. v.init(x,y - 1,z,di + 1);
  45. q.push(v);
  46. v.init(x,y,z + 1,di + 1);
  47. q.push(v);
  48. v.init(x,y,z - 1,di + 1);
  49. q.push(v);
  50. vis[x][y][z] = 1;
  51. }
  52. close = INT_MAX;
  53. cin >> n;
  54. string s,name;
  55. name = "None!";
  56. while(n--){
  57. cin >> s >> x >> y >> z;
  58. if(d[z][x][y - 1] != -1 && close > d[z][x][y - 1])
  59. close = d[z][x][y - 1], name = s;
  60. else if(d[z][x][y - 1] != -1 && close == d[z][x][y - 1] && s < name)
  61. close = d[z][x][y - 1], name = s;
  62. }
  63. cout << name << " ";
  64. if(close < INT_MAX)
  65. cout << close << "\n";
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement