Alx09

Untitled

Mar 18th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. bool Map[1001][1001];
  7. int n, m;
  8. queue < pair < int,int > > coada;
  9. void citire()
  10. {
  11. ifstream f("traversare.in");
  12. f >> n >> m;
  13. for(int j = 1 ; j <= m; j++)
  14. {
  15. f >> Map[1][j];
  16. if(Map[1][j] == 0) coada.push(make_pair(1,j)),Map[1][j] = 1;
  17. }
  18. for (int i = 2 ; i <= n ; i++)
  19. for(int j = 1;j <= m; j++)f >> Map[i][j];
  20.  
  21. f.close();
  22. }
  23. bool ok(int i,int j)
  24. {
  25. if ( i < 1 || j < 1 || i > n || j > m) return false;
  26. if (Map[i][j] != 0) return false;
  27. return true;
  28. }
  29. void lee()
  30. { int di[] = { 1, 0, 0};
  31. int dj[] = { 0 , -1, 1};
  32. int i, j, i_urm, j_urm;
  33. while(!coada.empty())
  34. {
  35. i = coada.front().first;
  36. j = coada.front().second;
  37. coada.pop();
  38. for ( int dir = 0; dir <= 2; dir++)
  39. {
  40. i_urm = i + di[dir];
  41. j_urm = j + dj[dir];
  42. if(ok(i_urm,j_urm))
  43. {
  44. coada.push(make_pair(i_urm,j_urm));
  45. Map[i_urm][j_urm] = Map[i][j] + 1;
  46. }
  47. }
  48. }
  49.  
  50.  
  51. }
  52. int main()
  53. {
  54. int minim = 20000;
  55. for (int i = 1 ; i <= m ;i++)
  56. if(Map[n][i] < minim) minim = Map[n][i];
  57. ofstream g("traversare.out");
  58. g << minim;
  59. g.close();
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment