Alx09

Untitled

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