Advertisement
GastonFontenla

Untitled

Jun 7th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
  7. int dy[] = {1, 1, 1, 0, 0, -1, -1, -1};
  8.  
  9. bool isValid(int x, int y, int alto, int ancho)
  10. {
  11.     return (0 <= x && x < alto && 0 <= y && y < ancho);
  12. }
  13.  
  14. int cant;
  15.  
  16. void floodfill(vector <string> &m, int x, int y)
  17. {
  18.     cant++;
  19.     m[x][y] = '0';
  20.     for(int i=0; i<8; i++)
  21.     {
  22.         int a = x+dx[i];
  23.         int b = y+dy[i];
  24.         if(isValid(a, b, m.size(), m[0].size()) && m[a][b] == '1')
  25.         {
  26.             floodfill(m, a, b);
  27.         }
  28.     }
  29. }
  30.  
  31. int main()
  32. {
  33.     int tc;
  34.     cin >> tc;
  35.     string tmp;
  36.     getline(cin, tmp);
  37.     getline(cin, tmp);
  38.     while(tc--)
  39.     {
  40.         vector <string> vec;
  41.         getline(cin, tmp);
  42.         while(tmp.size())
  43.         {
  44.             vec.push_back(tmp);
  45.             getline(cin, tmp);
  46.         }
  47.         int maximo = 0;
  48.         for(int i=0; i<vec.size(); i++)
  49.         {
  50.             for(int j=0; j<vec[i].size(); j++)
  51.             {
  52.                 if(vec[i][j] == '1')
  53.                 {
  54.                     cant = 0;
  55.                     floodfill(vec, i, j);
  56.                     maximo = max(maximo, cant);
  57.                 }
  58.             }
  59.         }
  60.         cout << maximo << endl;
  61.         if(tc)
  62.             cout << endl;
  63.     }
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement