Advertisement
Alx09

Untitled

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