Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
- int dy[] = {1, 0, -1, 1, -1, 1, 0, -1};
- vector<vector<bool> >v;
- vector <string> dep;
- int ancho,alto,ca=0;
- bool esValido(int x, int y) ///Si existe
- {
- return (0 <= x && x < ancho && 0 <= y && y < alto);
- }
- void init(int width, int height)
- {
- ancho = width;
- alto = height;
- v = vector <vector <bool> > (alto, vector <bool> (ancho, false));
- dep = vector <string> (alto);
- }
- void floodfill(int x, int y)
- {
- v[x][y] = true;
- for(int i=0; i<8; i++)
- {
- int a = x + dx[i];
- int b = y + dy[i];
- if(esValido(b,a) && dep[a][b] == '@' && v[a][b] == false)
- floodfill(a, b);
- }
- }
- int main()
- {
- vector<int>res;
- int f,c,m,n;
- cin>>m>>n;
- while(m!=0 || n!=0)
- {
- init(n,m);
- for(f=0; f<m; f++)
- cin>>dep[f];
- for(f=0; f<m; f++)
- {
- for(c=0; c<n; c++)
- {
- if((dep[f][c]=='@') && (v[f][c]==false))
- {
- ca++;
- floodfill(f,c);
- }
- }
- }
- ///variable que informa cuantas veces se uso el floodfill
- res.push_back(ca);
- ca=0;
- cin>>m>>n;
- }
- int i;
- for(i=0; i<res.size(); i++)
- cout<<res[i]<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment