Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <fstream>
- using namespace std;
- ifstream f("alee.in");
- ofstream g ("alee.out");
- int di[4] = {0, 0,-1, 1};
- int dj[4] = {1,-1,0, 0};
- int Map[180][180], 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 >> stopx >> stopy;
- f >> startx >> starty;
- }
- bool ok(int i, int j)
- {
- if(i < 1 || j < 1 || i > n || j > m)
- return false;
- return true;
- }
- void Lee()
- {
- int i, j,i_urm, j_urm;
- 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));
- }
- }
- }
- }
- int main()
- {
- Read();
- Lee();
- g << Map[stopx][stopy];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment