Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #include "iostream"
  2. #include "queue"
  3. using namespace std;
  4.  
  5. struct momento
  6. {
  7. int x;
  8. int y;
  9. int p;
  10.  
  11. };
  12.  
  13. queue< momento> c;
  14. bool visitado[51][51];
  15. char mapa[51][51];
  16. int mover[4][2] = {{1,0}, {0,-1}, {0,1}, {-1,0}};
  17. int n;
  18.  
  19. int main()
  20. {
  21. cin.sync_with_stdio(0);
  22. cin.tie(0);
  23.  
  24. cin >> n;
  25. for(int i = 0; i < n; i++)
  26. for(int j = 0; j < n; j++)
  27. cin >> mapa[i][j];
  28. c.push((momento){0, 0, 1});
  29. while(not c.empty())
  30. {
  31. momento actual = c.front();
  32. visitado[actual.x][actual.y] = true;
  33.  
  34. for(int i = 0; i < n; i++)
  35. {
  36. for(int j = 0; j < n; j++)
  37. cout << visitado[i][j]?"1 ": "0 ";
  38. cout << endl;
  39. }
  40. cout << endl;
  41. if(actual.x == n - 1 and actual.y == n - 1)
  42. {
  43. cout << actual.p << "\n";
  44. return 0;
  45. }
  46. for(int i = 0; i < 4; i ++)
  47. {
  48. int posx = actual.x + mover[0][i];
  49. int posy = actual.y + mover[1][i];
  50.  
  51. if(posx >= 0 and posx < n and
  52. posy >= 0 and posy < n and
  53. not visitado[posx][posy] and mapa[posx][posy] != '#')
  54. {
  55. //cout << "49 " << posx << " " << posy << "\t" <<actual.p << endl;
  56. if(mapa[posx][posy] >= 48 and mapa[posx][posy] <= 57)
  57. {
  58. //cout << char(mapa[posx][posy]) << endl;
  59. int numero = int(mapa[posx][posy]) - 48;
  60. //cout << numero << endl;
  61. if(actual.p % numero - 1 == 0)
  62. c.push((momento){actual.x, actual.y, actual.p + 1});
  63. else
  64. c.push((momento){posx, posy, actual.p + 1});
  65. }
  66. else
  67. c.push((momento){posx, posy, actual.p + 1});
  68. }
  69. }
  70. c.pop();
  71. }
  72.  
  73. cout << "-1\n";
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement