Advertisement
Guest User

E

a guest
Jan 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <queue>
  4. #define _ ios::sync_with_stdio(0);
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int v[105][105], dx[] = {-1, 0,1,0,-1};
  10. bool flagg[105][105];
  11.  
  12. int main()
  13. {_
  14.     queue<int> q;
  15.     int n, i, j, m, t;
  16.     cin>>n;
  17.     cin>>i>>j;
  18.  
  19.     for(int k = 1; k<=n; ++k)
  20.         for(int h = 1; h<=n; ++h)
  21.             cin>>v[k][h];
  22.  
  23.     q.push(i);
  24.     q.push(j);
  25.     n = 1;
  26.     flagg[i][j] = 1;
  27.  
  28.     while(!q.empty())
  29.     {
  30.         i = q.front();
  31.         q.pop();
  32.         j = q.front();
  33.         q.pop();
  34.  
  35.         for(int k = 0; k<4; ++k)
  36.         {
  37.             m = i+dx[k];
  38.             t = j+dx[k+1];
  39.             if(!flagg[m][t] && v[m][t]>= v[i][j])
  40.             {
  41.                 q.push(m);
  42.                 q.push(t);
  43.                 n++;
  44.                 flagg[m][t]=1;
  45.             }
  46.         }
  47.     }
  48.  
  49.     cout<<n<<endl;
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement