velimir

Barok 2

Mar 1st, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <vector>
  5. #include <string>
  6. #include <stack>
  7. #include <queue>
  8.  
  9. using namespace std;
  10.  
  11. int  meseci, l, w, b;
  12. bool mat[3000][3000];
  13.  
  14. void BFS(int a, int b, int c)
  15. {
  16.     queue<int> redx, redy, mes;
  17.     redx.push(a);
  18.     redy.push(b);
  19.     mes.push(c);
  20.     while(!redx.empty())
  21.     {
  22.         int mesec = mes.front();
  23.         mes.pop();
  24.         int m = redx.front();
  25.         int n = redy.front();
  26.         redx.pop();
  27.         redy.pop();
  28.         if(mat[m][n+1]!= true and n+1<w and mesec+1<=meseci)              { redx.push(m); redy.push(n+1); mat[m][n+1] = true; mes.push(mesec+1);}
  29.         if(mat[m+1][n+1]!= true and n+1<w and m+1<l and mesec+1<=meseci)  { redx.push(m+1); redy.push(n+1); mat[m+1][n+1] = true; mes.push(mesec+1);}
  30.         if(mat[m+1][n]!= true and m+1<l and mesec+1<=meseci)              { redx.push(m+1); redy.push(n); mat[m+1][n] = true; mes.push(mesec+1);}
  31.         if(mat[m-1][n-1]!= true and n-1>=0 and m-1>=0 and mesec+1<=meseci){ redx.push(m-1); redy.push(n-1); mat[m-1][n-1] = true; mes.push(mesec+1);}
  32.         if(mat[m-1][n]!= true and m-1>=0 and mesec+1<=meseci)             { redx.push(m-1); redy.push(n); mat[m-1][n] = true; mes.push(mesec+1);}
  33.         if(mat[m-1][n+1]!= true and n+1<w and m-1>=0 and mesec+1<=meseci) { redx.push(m-1); redy.push(n+1); mat[m-1][n+1] = true; mes.push(mesec+1);}
  34.         if(mat[m][n-1]!= true and n-1>=0 and mesec+1<=meseci)             { redx.push(m); redy.push(n-1); mat[m][n-1] = true; mes.push(mesec+1);}
  35.         if(mat[m+1][n-1]!= true and n-1>=0 and m+1<l and mesec+1<=meseci) { redx.push(m+1); redy.push(n-1); mat[m+1][n-1] = true; mes.push(mesec+1);}
  36.     }
  37. }
  38.  
  39. int main()
  40. {
  41.     ios::sync_with_stdio(false);
  42.     int i, j, k, x, y, ri, ci, coutie=0;
  43.     cin >> l >> w >> meseci >> b;
  44.     for(i=0; i<b; i++)
  45.     {
  46.         cin >> ri >> ci;
  47.         mat[ri-1][ci-1] = true;
  48.         BFS(ri-1, ci-1, 0);
  49.     }
  50.     for(i=0; i<l; i++)
  51.         for(j=0; j<w; j++)
  52.             if(mat[i][j] == true)coutie++;
  53.     cout << coutie;
  54.             return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment