Alx09

Untitled

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