Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <fstream>
- using namespace std;
- ifstream f("ubuph.in");
- ofstream g ("ubuph.out");
- int di[4] = {0, 1,0,-1};
- int dj[4] = {1,0,-1, 0};
- long long Map[1001][1001],Map2[1001][1001], n, m;
- int startx, starty, stopx, stopy;
- queue < pair < int, int > > coada;
- void Read()
- {
- f >> n >> m;
- for(int i=1; i <= n; i++)
- for (int j=1 ;j <= m; j++)
- {
- f >> Map[i][j];
- }
- f >> startx >> starty;
- f >> stopx >> stopy;
- }
- bool ok(int i, int j)
- {
- if(i < 1 || j < 1 || i > n || j > m)
- return false;
- if(Map2[i][j] == 1) return false;
- return true;
- }
- void Lee()
- {
- int i, j,i_urm, j_urm;
- Map2[startx][starty] =1;
- coada.push(make_pair(startx,starty));
- while( !coada.empty())
- {
- i = coada.front().first;
- j = coada.front().second;
- coada.pop();
- for (int directie=0 ; directie < 4 ;directie++)
- {
- i_urm = i + di[directie];
- j_urm = j + dj[directie];
- if(ok(i_urm,j_urm))
- {
- Map[i_urm][j_urm] += Map[i][j] ;
- coada.push(make_pair(i_urm,j_urm));
- Map2[i_urm][j_urm]=1;
- }
- }
- }
- }
- int main()
- {
- Read();
- Lee();
- g <<Map[stopx][stopy];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment