Alx09

Untitled

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